mirror of
https://github.com/progval/Limnoria.git
synced 2025-05-04 09:21:07 -05:00
Math: Fix log/log10 return type.
They used to always return complex numbers, instead of floats on float argument.
This commit is contained in:
parent
4528a847e4
commit
5c10bea7aa
@ -61,11 +61,11 @@ BIN_OPS = {
|
|||||||
MATH_CONSTANTS = 'e inf nan pi tau'.split()
|
MATH_CONSTANTS = 'e inf nan pi tau'.split()
|
||||||
SAFE_MATH_FUNCTIONS = (
|
SAFE_MATH_FUNCTIONS = (
|
||||||
'acos acosh asin asinh atan atan2 atanh copysign cos cosh degrees erf '
|
'acos acosh asin asinh atan atan2 atanh copysign cos cosh degrees erf '
|
||||||
'erfc exp expm1 fabs fmod frexp fsum gamma hypot ldexp lgamma log log10 '
|
'erfc exp expm1 fabs fmod frexp fsum gamma hypot ldexp lgamma '
|
||||||
'log1p log2 modf pow radians remainder sin sinh tan tanh'
|
'log1p log2 modf pow radians remainder sin sinh tan tanh'
|
||||||
).split()
|
).split()
|
||||||
SAFE_CMATH_FUNCTIONS = (
|
SAFE_CMATH_FUNCTIONS = (
|
||||||
'acos acosh asin asinh atan atanh cos cosh exp inf infj log log10 '
|
'acos acosh asin asinh atan atanh cos cosh exp inf infj '
|
||||||
'nanj phase polar rect sin sinh tan tanh tau'
|
'nanj phase polar rect sin sinh tan tanh tau'
|
||||||
).split()
|
).split()
|
||||||
|
|
||||||
@ -78,6 +78,18 @@ def _sqrt(x):
|
|||||||
else:
|
else:
|
||||||
return math.sqrt(x)
|
return math.sqrt(x)
|
||||||
|
|
||||||
|
def _log(x):
|
||||||
|
if isinstance(x, complex) or x < 0:
|
||||||
|
return cmath.log(x)
|
||||||
|
else:
|
||||||
|
return math.log(x)
|
||||||
|
|
||||||
|
def _log10(x):
|
||||||
|
if isinstance(x, complex) or x < 0:
|
||||||
|
return cmath.log10(x)
|
||||||
|
else:
|
||||||
|
return math.log10(x)
|
||||||
|
|
||||||
def _cbrt(x):
|
def _cbrt(x):
|
||||||
return math.pow(x, 1.0/3)
|
return math.pow(x, 1.0/3)
|
||||||
|
|
||||||
@ -96,6 +108,8 @@ SAFE_ENV.update({
|
|||||||
'factorial': _factorial,
|
'factorial': _factorial,
|
||||||
'sqrt': _sqrt,
|
'sqrt': _sqrt,
|
||||||
'cbrt': _cbrt,
|
'cbrt': _cbrt,
|
||||||
|
'log': _log,
|
||||||
|
'log10': _log10,
|
||||||
'ceil': lambda x: float(math.ceil(x)),
|
'ceil': lambda x: float(math.ceil(x)),
|
||||||
'floor': lambda x: float(math.floor(x)),
|
'floor': lambda x: float(math.floor(x)),
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user