math模組常用函式總結

2021-09-25 20:12:54 字數 620 閱讀 1459

函式

描述格式

返回值ceil()

向上取整操作

math.ceil(數值)

整型floor()

向下取整操作 (對比內建round)

math.floor(數值))

整型pow()

計算乙個數值的n次方

math.pow(底數,指數)

浮點型sqrt()

開平方運算

math.sqrt(數值)

數值fabs()

計算乙個數值的絕對值(對比內建abs)

math.fabs(數值)

非負浮點數

modf()

將乙個數值拆分為整數和小數兩部分組成元組

math.modf(數值)

(小數部分,整數部分)

copysign()

將引數第二個數值的正負號拷貝給第乙個

math.copysign(數值1,數值2)

新的數值

fsum()

將乙個容器資料中的資料進行求和運算(對比內建sum)

math.fsum(容器)

浮點型結果

pi圓周率,但不是函式

math.pi

浮點型pi

Math物件 函式總結

math的官方函式 1.math.random 作用 隨機產生0 1之間的數,不包括1 var t parseint math.random 10 隨機取出0 10之間的乙個整數,不包括10 2.math.round n 作用 四捨五入取整 math.round 4.2 結果是4 3.math.ce...

Math和Random常用函式

math static int max int a,int b static long max long a,long b static double max double a,double b static float max float a,float b 同理min的各種過載 static t...

python中math常用函式

import math 先導入math包print math.pi 列印pi的值3.14159265359print math.radians 180 把度數轉化為弧度,即180 pi3.14159265359sin90 math.sin math.pi 2 計算sin pi 2 sin180 ma...