Difference between revisions of "Math.frexp"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
+
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Class:''' [[math]]<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/math|math]]<br/>
+
 
=== <translate>Description</translate> ===
+
=== Description ===
<translate>Returns m and e such that v = m2^e, e is an integer and the absolute value of m is in the range [0.5, 1) (or zero when v is zero).</translate>
+
Used to split a floating-point number (v) into a normalized fraction (a mantissa) and an integer exponent.
<source lang="lua">
+
<syntaxhighlight lang="lua">
(number) = math.frexp(v)
+
(number) (number) = math.frexp(v)
</source>
+
</syntaxhighlight>
=== <translate>Parameters</translate> ===
+
 
'''v''': (number) <translate>value</translate> <br/>
+
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.
=== <translate>Return values</translate> ===
+
 
'''<translate>Returns</translate>''' (number) <translate>result</translate><br/>
+
=== Parameters ===
 +
'''v''': (number) value<br/>
 +
 
 +
=== Return values ===
 +
'''Returns''' (number) the mantissa, a multiplier in the range [0.5, 1) (normalized fraction)<br/>
 +
'''Returns''' (number) the exponent as an integer<br/>
 +
 
 +
=== 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
 +
</syntaxhighlight>
 +
 
 +
=== Note ===
 +
[[math.ldexp]] is the inverse operation.
  
 
{{Math}}
 
{{Math}}

Latest revision as of 15:30, 13 July 2023

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) -- mantissa 0.5125 exponent 5
print(m*2^n) -- 16.4

Note

math.ldexp is the inverse operation.