python数学模块Word文档格式.docx

上传人:b****5 文档编号:16333379 上传时间:2022-11-23 格式:DOCX 页数:7 大小:18.79KB
下载 相关 举报
python数学模块Word文档格式.docx_第1页
第1页 / 共7页
python数学模块Word文档格式.docx_第2页
第2页 / 共7页
python数学模块Word文档格式.docx_第3页
第3页 / 共7页
python数学模块Word文档格式.docx_第4页
第4页 / 共7页
python数学模块Word文档格式.docx_第5页
第5页 / 共7页
点击查看更多>>
下载资源
资源描述

python数学模块Word文档格式.docx

《python数学模块Word文档格式.docx》由会员分享,可在线阅读,更多相关《python数学模块Word文档格式.docx(7页珍藏版)》请在冰豆网上搜索。

python数学模块Word文档格式.docx

isnotafloat,delegatesto 

x.__ceil__(),whichshouldreturnan 

Integral 

value.

math.copysign(x, 

y)

Returnafloatwiththemagnitude(absolutevalue)of 

butthesignof 

y.Onplatformsthatsupportsignedzeros, 

copysign(1.0, 

-0.0) 

returns 

-1.0.

math.fabs(x)

Returntheabsolutevalueof 

x.

math.factorial(x)

Return 

factorial.Raises 

ValueError 

if 

isnotintegralorisnegative.

math.floor(x)

Returnthefloorof 

x,thelargestintegerlessthanorequalto 

isnotafloat,

delegatesto 

x.__floor__(),whichshouldreturnan 

math.fmod(x, 

fmod(x, 

y),asdefinedbytheplatformClibrary.NotethatthePythonexpression 

maynotreturnthesameresult.TheintentoftheCstandardisthat 

y) 

beexactly(mathematically;

toinfiniteprecision)equalto 

n*y 

forsomeinteger 

suchthattheresulthasthesamesignas 

andmagnitudelessthan 

abs(y).Python’s 

yreturnsaresultwiththesignof 

instead,andmaynotbeexactlycomputableforfloatarguments.Forexample, 

fmod(-1e-100, 

1e100) 

is 

-1e-100,buttheresultofPython’s 

-1e-100 

1e100 

1e100-1e-100,whichcannotberepresentedexactlyasafloat,androundstothesurprising 

1e100.Forthisreason,function 

fmod() 

isgenerallypreferredwhenworkingwithfloats,whilePython’s 

ispreferredwhenworkingwithintegers.

math.frexp(x)

Returnthemantissaandexponentof 

asthepair 

(m, 

e). 

isafloatand 

isanintegersuchthat 

== 

2**e 

exactly.If 

iszero,returns 

(0.0, 

0),otherwise 

0.5 

<

abs(m)<

 

1.Thisisusedto“pickapart”theinternalrepresentationofafloatinaportableway.

math.fsum(iterable)

Returnanaccuratefloatingpointsumofvaluesintheiterable.Avoidslossofprecisionbytrackingmultipleintermediatepartialsums:

>

sum([.1,.1,.1,.1,.1,.1,.1,.1,.1,.1])

0.9999999999999999

fsum([.1,.1,.1,.1,.1,.1,.1,.1,.1,.1])

1.0

Thealgorithm’saccuracydependsonIEEE-754arithmeticguaranteesandthetypicalcasewheretheroundingmodeishalf-even.Onsomenon-Windowsbuilds,theunderlyingClibraryusesextendedprecisionadditionandmayoccasionallydouble-roundanintermediatesumcausingittobeoffinitsleastsignificantbit.

Forfurtherdiscussionandtwoalternativeapproaches,seethe 

ASPNcookbookrecipesforaccuratefloatingpointsummation.

math.gcd(a, 

b)

Returnthegreatestcommondivisoroftheintegers 

and 

b.Ifeither 

or 

isnonzero,thenthevalueof 

gcd(a, 

b) 

isthelargestpositiveintegerthatdividesboth 

b.gcd(0, 

0) 

0.

Newinversion3.5.

math.isclose(a, 

b, 

*, 

rel_tol=1e-09, 

abs_tol=0.0)

True 

ifthevalues 

areclosetoeachotherand 

False 

otherwise.

Whetherornottwovaluesareconsideredcloseisdeterminedaccordingtogivenabsoluteandrelativetolerances.

rel_tol 

istherelativetolerance–itisthemaximumalloweddifferencebetween 

b,relativetothelargerabsolutevalueof 

b.Forexample,tosetatoleranceof5%,pass 

rel_tol=0.05.Thedefaulttoleranceis 

1e-09,whichassuresthatthetwovaluesarethesamewithinabout9decimaldigits. 

mustbegreaterthanzero.

abs_tol 

istheminimumabsolutetolerance–usefulforcomparisonsnearzero. 

abs_tolmustbeatleastzero.

Ifnoerrorsoccur,theresultwillbe:

abs(a-b) 

max(rel_tol 

max(abs(a), 

abs(b)),abs_tol).

TheIEEE754specialvaluesof 

NaN, 

inf,and 

-inf 

willbehandledaccordingtoIEEErules.Specifically, 

NaN 

isnotconsideredclosetoanyothervalue,including 

NaN. 

inf 

areonlyconsideredclosetothemselves.

Seealso:

PEP485 

–Afunctionfortestingapproximateequality

math.isfinite(x)

isneitheraninfinitynoraNaN,and 

otherwise.(Notethat 

0.0 

isconsideredfinite.)

Newinversion3.2.

math.isinf(x)

isapositiveornegativeinfinity,and 

math.isnan(x)

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1