1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

math: implement pow in pure V (#12105)

This commit is contained in:
playX
2021-10-08 17:44:55 +03:00
committed by GitHub
parent 60add6cc28
commit a8ace2c41c
10 changed files with 222 additions and 69 deletions

View File

@@ -475,3 +475,17 @@ pub fn rem_64(hi u64, lo u64, y u64) u64 {
_, rem := div_64(hi % y, lo, y)
return rem
}
// normalize returns a normal number y and exponent exp
// satisfying x == y × 2**exp. It assumes x is finite and non-zero.
pub fn normalize(x f64) (f64, int) {
smallest_normal := 2.2250738585072014e-308 // 2**-1022
if (if x > 0.0 {
x
} else {
-x
}) < smallest_normal {
return x * (u64(1) << u64(52)), -52
}
return x, 0
}