Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Create a float from an exponent and mantissa
Compute an XFL (xls17) floating point from the provided exponent and mantissa
Return that XFL as an int64_t
C
C
exponent
int32_t
An exponent in the range -96
to 80
mantissa
int64_t
A mantissa. If negative then the sign of the float is negative.
🚧CautionWhen setting a mantissa that is greater or fewer than 16 decimal digits the exponent will be adjusted to ensure the mantissa is exactly 16 digits. This adjustment may result in an
INVALID_FLOAT
in some circumstances.
📘Special caseXFL canonical 0 is also 0 in the enclosing number. Thus there is never a need to call
float_set(0,0);
int64_t
The XFL (xls17) enclosing number
If negative, an error:
INVALID_FLOAT
- The adjustment of the mantissa to 16 digits produced an under or overflow.
Add two XFL numbers together
Compute the addition of two XFL (xls17) floating point numbers
Return a new XFL as an int64_t
C
C
float1
int64_t
An XFL floating point enclosing number representing the first operand to the addition
float2
int64_t
An XFL floating point enclosing number representing the second operand to the addition
📘HintTo subtract two floats use
float_negate
on the second float then usefloat_sum
.
int64_t
The XFL (xls17) enclosing number
If negative, an error:
INVALID_FLOAT
- one of the supplied parameters was not a valid XFL enclosing number
OVERFLOW
- the result of the addition was too large to store in an XFL.
Negate an XFL floating point number
Multiply an XFL by -1
Return a new XFL as an int64_t
C
C
📘Special caseThe negation of Canonical Zero is Canonical Zero. Unlike some floating point standards (such as IEEE) there is no "negative zero" in XFL.
float1
int64_t
An XFL floating point enclosing number
int64_t
The XFL (xls17) enclosing number
If negative, an error:
INVALID_FLOAT
- one of the supplied parameters was not a valid XFL enclosing number
Multiply two XFL numbers together
Compute the multiplication of two XFL (xls17) floating point numbers
Return a new XFL as an int64_t
C
C
float1
int64_t
An XFL floating point enclosing number representing the first operand to the multiplication
float2
int64_t
An XFL floating point enclosing number representing the second operand to the multiplication
🚧CautionCertain multiplications may overflow, which return with an
INVALID_FLOAT
error. However an underflow returns as XFL Canonical Zero (i.e. enclosing number = 0).
int64_t
The XFL (xls17) enclosing number
If negative, an error:
INVALID_FLOAT
- one of the supplied parameters was not a valid XFL enclosing number
OVERFLOW
- the result of the multiplication was too large to store in an XFL.
Return the number 1 represented in an XFL enclosing number
Return one(1
) as an XFL int64_t
C
C
This function has no parameters.
int64_t
The XFL (xls17) enclosing number
Read a serialized amount into an XFL
Read a serialized floating point number.
If there are more fields/data after the serialized floating pointer number then ignore them.
Return it as an XFL enclosing number
C
C
read_ptr
uint32_t
Pointer to a buffer contianing the serialized XFL. May be null.
read_len
uint32_t
The length of the buffer.
int64_t
The number of bytes written to the output buffer.
If negative, an error:
NOT_AN_OBJECT
- the supplied buffer did not contain a valid serialized floating point number
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
Divide an XFL by another XFL floating point number
Divide an XFL by another XFL
Return a new XFL as an int64_t
C
C
float1
int64_t
An XFL floating point enclosing number to act as numerator
float2
int64_t
An XFL floating point enclosing number to act as denominator
int64_t
The XFL (xls17) enclosing number
If negative, an error:
INVALID_FLOAT
- the supplied parameter was not a valid XFL enclosing number or the division resulted in an XFL that cannot be represented.
DIVISION_BY_ZERO
- the supplied parameter was zero.
Perform a comparison on two XFL floating point numbers
Evaluate a comparison of two XFL floating point numbers
Return the result of the comparison as a boolean encoded in an int64_t.
C
C
🚧CautionAlways verify the function returned
1
rather thannon-zero
, as negative error codes will be classed asnon-zero
.
Multiply an XFL floating point by a non-XFL numerator and denominator
Compute the multiplication of an XFL (xls17) floating point number and the quotient of two integers
Return a new XFL as an int64_t
C
C
🚧CautionCertain multiplications may overflow, which return with an
INVALID_FLOAT
error. However an underflow returns as XFL Canonical Zero (i.e. enclosing number = 0).
float1
int64_t
An XFL floating point enclosing number representing the first operand to the comparison
float2
int64_t
An XFL floating point enclosing number representing the second operand to the comparison
mode
uint32_t
A bit-flag field consisting of any of (or any logically valid combination of) the following flags:
COMPARE_LESS
COMPARE_EQUAL
COMPARE_GREATER
Valid combinations are:
COMPARE_LESS
| COMPARE_GREATER
- Not equal
COMPARE_LESS
| COMPARE_EQUAL
- Less than or equal to
COMPARE_GREATER
| COMPARE_EQUAL
- Greater than or equal to
int64_t
0
if the comparison was logically false.
1
if the comparison was logically true.
If negative, an error:
INVALID_FLOAT
- one of the supplied parameters was not a valid XFL enclosing number
INVALID_ARGUMENT
- invalid combination of supplied comparison flags.
float1
int64_t
An XFL floating point enclosing number representing the first operand to the multiplication
round_up
uint32_t
If non-zero all computations will be rounded up
numerator
uint32_t
The numerator of the quotient that the float will be multiplied by
denominator
uint32_t
The denominator of the quotient that the float will be multiplied by
int64_t
The XFL (xls17) enclosing number
If negative, an error:
INVALID_FLOAT
- one of the supplied parameters was not a valid XFL enclosing number
OVERFLOW
- the result of the multiplication was too large to store in an XFL.
DIVISION_BY_ZERO
- the supplied denominator was zero.
Get the mantissa of an XFL enclosing number
Return the mantissa part of an XFL as an unsigned integer
C
C
📘HintThe mantissa of a negative XFL is positive. Use
float_sign
to get the sign.
float1
int64_t
An XFL floating point enclosing number
int64_t
The mantissa of the XFL
If negative, an error:
INVALID_FLOAT
- the supplied parameter was not a valid XFL enclosing number
Get the sign of an XFL enclosing number
Return 1
if the XFL is negative, otherwise return 0
C
C
📘HintThe sign bit inside the XFL is the
0
when the XFL is negative, however this function follows the standard computing convention to return1
if it is negative.
float1
int64_t
An XFL floating point enclosing number
int64_t
The sign of the XFL:
0
if positive, 1
if negative.
If negative, an error:
INVALID_FLOAT
- the supplied parameter was not a valid XFL enclosing number
Output an XFL as a serialized object
Read an XFL floating point number and optionally a field code and currency code
Write a serialized amount to write_ptr
according to the parameters provided
C
C
📘HintTo output an
XAH
amount prepopulate the field code in the output buffer then pass the output buffer incremented to the new start and0
as field_code
Compute the decimal log of an XFL
Compute a the decimal logarithm of an XFL number
Return the new XFL
❗️WarningDue to speed constraints,
float_log
converts the argument to an IEEE base-2 double precision floating point before applying base 10 log. Therefore the returned result will often contain less precision than expected.
C
C
🚧WarningIf a negative number is passed the function will return
COMPLEX_NOT_SUPPORTED
if the root is an even root.
Compute the nth root of an XFL
Compute a the nth
root of an XFL number
Return the new XFL
❗️WarningDue to speed constraints,
float_root
converts the argument to an IEEE base-2 double precision floating point before applying n-th root. Therefore the returned result will often contain less precision than expected. If you need better precision you should consider dividing your XFL into a high and a low product then individually take the square roots of those products and multiply the results together.
C
C
🚧WarningIf a negative number is passed the function will return
COMPLEX_NOT_SUPPORTED
if the root is an even root.
Get the exponent of an XFL enclosing number
🚧 Replaced by macroThis function was replaced by a macro. Please use the macro below in your code instead. To check the validity of the XFL please use float_mantissa in conjunction with this macro.
Return the exponent part of an XFL as a signed integer
Because exponents can be negative, and because negatives are reserved for error states, exponents cannot be returned from functions. Therefore this function has become a macro as shown below.
C
C
Convert an XFL floating point into an integer (floor)
Left shift (multiply by 10) the XFL by the number of specified decimal places
Convert the resulting XFL to an integer, discarding any remainder
Return the integer
C
C
📘HintNegative return values are reserved for error codes. Therefore if you need to execute this function against a negative XFL you should use
absolute = 1
write_ptr
uint32_t
Pointer to a buffer of a suitable size to store the serialized amount field. Recommend at least 48 bytes.
write_len
uint32_t
The length of the output buffer.
cread_ptr
uint32_t
Pointer to a buffer contianing the currency code to serialize into the output. May be null.
cread_len
uint32_t
The length of the currency code. This must be 20 or 3 or 0 (null).
iread_ptr
uint32_t
Pointer to a buffer containing the issuer's Account ID to serialize into the output. May be null.
iread_len
uint32_t
The length of the issuer's Account ID. This must be either 20 or 0 (null).
float1
int64_t
An XFL floating point enclosing number to serialize.
field_code
uint32_t
The sf
field code to prefix the serialized amount with. E.g. sfAmount
.
If this field is 0xFFFFFFFFU
(i.e. (uint32_t)(-1)
) then no field code is prepended to the output, and no issuer or currency code is appended, but serialization proceeds as a floating point amount.
If this field is 0 no field code is prepended to the output, and no issuer or currency code is appended, but serialization proceeds as though the amount is an XRP native amount rather than a floating point.
int64_t
The number of bytes written to the output buffer.
If negative, an error:
INVALID_FLOAT
- the supplied float was not a valid XFL enclosing number
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
INVALID_ARGUMENT
- If instructed to output as XRP
or without field code
then all non-write pointers and lengths should be 0 (null).
TOO_SMALL
- The output buffer was too small to receive the serialized object.
XFL_OVERFLOW
- Expressing the output caused an overflow during normalization.
float1
int64_t
An XFL floating point enclosing number representing the floating point number to take the logarithm of
int64_t
The computed logarithm
If negative, an error:
INVALID_FLOAT
- the supplied parameter was not a valid XFL enclosing number
COMPLEX_NOT_SUPPORTED
- the supplied parameter was a negative number which would result in a complex return value.
float1
int64_t
An XFL floating point enclosing number representing the floating point number to take the square root of
n
uint32_t
The root to compute, for example 2
is a square root.
int64_t
The computed nth root
If negative, an error:
INVALID_FLOAT
- the supplied parameter was not a valid XFL enclosing number
COMPLEX_NOT_SUPPORTED
- the supplied parameter was a negative number which would result in a complex root.
float1
int64_t
An XFL floating point enclosing number
float1
int64_t
An XFL floating point enclosing number
int64_t
The XFL (xls17) enclosing number
If negative, an error:
INVALID_FLOAT
- the supplied parameter was not a valid XFL enclosing number or the division resulted in an XFL that cannot be represented.
DIVISION_BY_ZERO
- the supplied parameter was zero.
float1
int64_t
An XFL floating point enclosing number representing the first operand to the addition
decimal_places
uint32_t
The number of places to shift the decimal to the right before computing the floor of the floating point.
absolute
uint32_t
If 1
also take the absolute of the value before returning it.
int64_t
The computed positive integer
If negative, an error:
INVALID_FLOAT
- one of the supplied parameters was not a valid XFL enclosing number
INVALID_ARGUMENT
- attempted to specify more than 15 decimal places.
CANT_RETURN_NEGATIVE
- attempted to return a negative integer but this is not allowed, use absolute = 1