Wikifunctions:Type proposals/float64
Summary
IEEE 754 double-precision floating-point format is a widely supported floating-point number. Note this type will natively support Inf and NaN. It can also precisely represent integer with no more than 53 bits.
Uses
Structure
There are two potential way to store a float64:
- stored as raw format (8 bytes)
- stored as lowercase string, which has format (nan|-?inf|(0|[1-9]\d*)\.\d+|-?[1-9]\.\d+e[+-][1-9]\d{0,2})
- store exponent and significand precision as two non-negative integer and sign bit as boolean
Example values
Value 0
{
"type": "float64",
"value": "0.0"
}
|
{
"Z1K1": "Zxxx",
"ZxxxK1": "0.0"
}
|
Persistent objects
There are some constants meaningful to store as persistent objects, such as pi and e.
Validator
The validator ensures that:
- it is a valid potential floating point format ([Nn][Aa][Nn]|[+-]?[Ii][Nn][Ff]|[+-]?(\d+.\d*|.\d+)([Ee][+-]?\d+)?)
- it is in canonical form (e.g. 100e100 is not in canonical form, since str(float("100e100"))="1e+102")
Identity
We need to define two kinds of identities:
- Precise identity (==) - Note many operations of float64 are precisely defined
- Identity with some allowed degree of error
Converting to code
Python
To convert string to float use float
; on the other hand use str
.
JavaScript
To convert string to float use parseFloat
; on the other hand use String
(note Inf and NaN should be then converted to lowercase).
Renderer
We simply use the canonical form string.
Parsers
Same as "Converting to code" above.
Alternatives
We can also Wikifunctions:Type proposals/float32, though neither Python nor JavaScript natively support such type.