Math.frexp

From GiderosMobile
Revision as of 15:28, 13 July 2023 by Hgy29 (talk | contribs) (Text replacement - "<source" to "<syntaxhighlight")

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. <syntaxhighlight lang="lua"> (number) (number) = math.frexp(v) </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). 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

<syntaxhighlight lang="lua"> local m, n = math.frexp(16.4) print("mantissa", m, "exponent", n) -- mantissa 0.5125 exponent 5 print(m*2^n) -- 16.4 </source>

Note

math.ldexp is the inverse operation.