Simplify reinterpret to require one type argument only, fixes #9

This commit is contained in:
dcodeIO
2018-01-13 01:15:09 +01:00
parent 2df318a7ec
commit dd596b015d
4 changed files with 49 additions and 69 deletions

View File

@ -117,15 +117,15 @@ store<f64>(8, load<f64>(8));
// reinterpretation
reinterpret<f32,i32>(1.25);
reinterpret<i32,f32>(25);
reinterpret<f64,i64>(1.25);
reinterpret<i64,f64>(25);
reinterpret<i32>(1.25);
reinterpret<f32>(25);
reinterpret<i64>(1.25);
reinterpret<f64>(25);
i = reinterpret<f32,i32>(1.25);
f = reinterpret<i32,f32>(25);
I = reinterpret<f64,i64>(1.25);
F = reinterpret<i64,f64>(25);
i = reinterpret<i32>(1.25);
f = reinterpret<f32>(25);
I = reinterpret<i64>(1.25);
F = reinterpret<f64>(25);
// host

View File

@ -1,7 +1,7 @@
export function fmod(x: f64, y: f64): f64 {
// the following is based on musl's implementation of fmod
var ux = reinterpret<f64,u64>(x);
var uy = reinterpret<f64,u64>(y);
var ux = reinterpret<u64>(x);
var uy = reinterpret<u64>(y);
var ex = <i32>(ux >> 52 & 0x7ff);
var ey = <i32>(uy >> 52 & 0x7ff);
var sx = <i32>(ux >> 63);
@ -59,7 +59,7 @@ export function fmod(x: f64, y: f64): f64 {
ux >>= -ex + 1;
}
ux |= <u64>sx << 63;
return reinterpret<u64,f64>(ux);
return reinterpret<f64>(ux);
}
assert(isNaN<f64>(fmod(1, NaN)));
@ -69,8 +69,8 @@ assert(fmod(9.2, 3.7) - 1.8 < f64.EPSILON); // not exactly 1.8 (as in C)
export function fmodf(x: f32, y: f32): f32 {
// the following is based on musl's implementation of fmodf
var ux = reinterpret<f32,u32>(x);
var uy = reinterpret<f32,u32>(y);
var ux = reinterpret<u32>(x);
var uy = reinterpret<u32>(y);
var ex = <i32>(ux >> 23 & 0xff);
var ey = <i32>(uy >> 23 & 0xff);
var sx = ux & 0x80000000;
@ -128,7 +128,7 @@ export function fmodf(x: f32, y: f32): f32 {
ux >>= -ex + 1;
}
ux |= sx;
return reinterpret<i32,f32>(ux);
return reinterpret<f32>(ux);
}
assert(isNaN<f32>(fmodf(1, NaN)));