Difference between revisions of "Math.frexp"
From GiderosMobile
Line 9: | Line 9: | ||
</source> | </source> | ||
− | Returns m and e such that v = m*2^e, e is an integer and the absolute value of m is in the range [0.5, 1) (or zero when v is zero). | + | Returns m and e such that v = m*2^e, e is an integer and the absolute value of m is in the range [0.5, 1) (or zero when v is zero). The mantissa has the same sign as the argument v. |
=== Parameters === | === Parameters === | ||
Line 17: | Line 17: | ||
'''Returns''' (number) the mantissa, a multiplier in the range [0.5, 1) (normalized fraction)<br/> | '''Returns''' (number) the mantissa, a multiplier in the range [0.5, 1) (normalized fraction)<br/> | ||
'''Returns''' (number) the exponent as an integer<br/> | '''Returns''' (number) the exponent as an integer<br/> | ||
+ | |||
+ | === Example === | ||
+ | <source lang="lua"> | ||
+ | local m, n = math.frexp(16.4) | ||
+ | print("mantissa", m, "exponent", n) | ||
+ | print(m*2^n) | ||
+ | </source> | ||
=== Note === | === Note === |
Revision as of 09:29, 14 November 2022
Available since: Gideros 2011.6
Class: math
Description
Used to split a floating-point number (v) into a normalized fraction (a mantissa) and an integer exponent.
(number) (number) = math.frexp(v)
Returns m and e such that v = m*2^e, e is an integer and the absolute value of m is in the range [0.5, 1) (or zero when v is zero). The mantissa has the same sign as the argument v.
Parameters
v: (number) value
Return values
Returns (number) the mantissa, a multiplier in the range [0.5, 1) (normalized fraction)
Returns (number) the exponent as an integer
Example
local m, n = math.frexp(16.4)
print("mantissa", m, "exponent", n)
print(m*2^n)
Note
math.ldexp is the inverse operation.
- Math
- Math.abs
- Math.acos
- Math.asin
- Math.atan
- Math.atan2
- Math.ceil
- Math.clamp
- Math.cos
- Math.cosh
- Math.cross
- Math.deg
- Math.distance
- Math.distances
- Math.dot
- Math.edge
- Math.exp
- Math.fft
- Math.floor
- Math.fmod
- Math.frexp
- Math.ifft
- Math.inside
- Math.ldexp
- Math.length
- Math.log
- Math.log10
- Math.max
- Math.min
- Math.modf
- Math.nearest
- Math.noise
- Math.normalize
- Math.pow
- Math.rad
- Math.random
- Math.randomseed
- Math.raycast
- Math.round
- Math.sign
- Math.sin
- Math.sinh
- Math.sqrt
- Math.tan
- Math.tanh