
louise
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#1197 · main · 10 min 35 s
1Étoiles
0Forks
0Issues
| 1 | /// Conversions of `Float` (ADR 0035). |
| 2 | /// |
| 3 | /// float.from_int(3) // 3.0 |
| 4 | /// float.to_bits(1.0) // 4607182418800017408 |
| 5 | /// float.from_bits32(0x3F800000) // 1.0 |
| 6 | /// |
| 7 | /// The bits are IEEE 754's, as an `Int` in `[0, 2^64)` (or `[0, 2^32)` for |
| 8 | /// a single), so `-0.0` is `2^63`, a big integer. NaN payloads are kept. |
| 9 | |
| 10 | /// The nearest Float to `n` (ties to even); an infinity past the largest. |
| 11 | @extern c "tl_float_from_int" |
| 12 | pub fn from_int :: n: Int -> Float |
| 13 | |
| 14 | /// The 64 bits of a Float. |
| 15 | @extern c "tl_float_to_bits" |
| 16 | pub fn to_bits :: x: Float -> Int |
| 17 | |
| 18 | /// The Float whose bits are the low 64 bits of `n`. |
| 19 | @extern c "tl_float_from_bits" |
| 20 | pub fn from_bits :: n: Int -> Float |
| 21 | |
| 22 | /// `x` rounded to a 32-bit single (to nearest, ties to even), its bits. |
| 23 | @extern c "tl_float_to_bits32" |
| 24 | pub fn to_bits32 :: x: Float -> Int |
| 25 | |
| 26 | /// The single whose bits are the low 32 bits of `n`, as a Float (exact). |
| 27 | @extern c "tl_float_from_bits32" |
| 28 | pub fn from_bits32 :: n: Int -> Float |
| 29 | |
| 30 | /// The Float written in `s` (decimal, exponent allowed), or an `Error` |
| 31 | /// naming the text that is not one. |
| 32 | pub fn parse :: s: String -> Result<Float, String> |
| 33 | { |
| 34 | let (ok, f) = parse_raw s |
| 35 | if ok |
| 36 | { |
| 37 | Ok(f) |
| 38 | } |
| 39 | else |
| 40 | { |
| 41 | Error("not a float: " <> debug s) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | @extern c "tl_float_parse" |
| 46 | fn parse_raw :: s: String -> (Bool, Float) |