-
Notifications
You must be signed in to change notification settings - Fork 102
Add tests against MPFR for scalbn{f}
and ldexp{f}
#392
Conversation
crates/libm-test/src/mpfloat.rs
Outdated
fn run(this: &mut Self::MpTy, input: Self::RustArgs) -> Self::RustRet { | ||
this.0.assign(input.0); | ||
this.1.assign(2.0); | ||
this.1.pow_assign(input.1); | ||
let ord = this.0.mul_assign_round(&this.1, Nearest); | ||
prep_retval::<Self::FTy>(&mut this.0, ord) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This discards the rounding of 2 ^ exp
which should be okay since powers of two are representable if within range. Somebody should double check this though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah this doesn't work because scalbn(INF, -HUGE)
works out to INF * 0 = NaN
, but the result should be infinity.
For reference, from the C spec:
scalbn(±0, n)
returns±0
.scalbn(x, 0)
returnsx
.scalbn(±∞, n)
returns±∞
.If the calculation does not overflow or underflow, the returned value is exact and independent of the current rounding direction mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after checking the docs, what you want is Float::shl
, if you're not immediately converting back to a primitive float you'll probably also want to call subnormalize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can look at subnormalize_ieee_round
's source for an idea of how to use subnormalize
, i'm assuming rust may gain support for non-ieee floats such as bf16 or f80.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that does seem to work simpler than what I had. The call to prep_retval
does call subnormalize_ieee_round
before casting to the float type (link), I don't think bf16
uses libm
(unlike f16
, all bf16
ops may be done at f32 precision right?) but this will probably need to be adjusted once we add the x87 float type. Easiest to just cross that bridge later though, I'm just getting started with f16
/f128
here.
scalbn[f]
and ldexp[f]
scalbn{f}
and ldexp{f}
02124db
to
20cf129
Compare
20cf129
to
07b0681
Compare
No description provided.