clamp ldexp exponent to i16
This commit is contained in:
parent
3ae01a64bc
commit
0743ed631e
1 changed files with 10 additions and 1 deletions
|
|
@ -597,7 +597,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
"_ldexp" | "ldexp" | "scalbn" => {
|
||||
let x = this.read_scalar(args[0])?.to_f64()?;
|
||||
let exp = this.read_scalar(args[1])?.to_i32()?;
|
||||
let res = x.scalbn(exp.try_into().unwrap());
|
||||
// Saturating cast to i16. Even those are outside the valid exponent range to
|
||||
// `scalbn` below will to its over/underflow handling.
|
||||
let exp = if exp > i16::max_value() as i32 {
|
||||
i16::max_value()
|
||||
} else if exp < i16::min_value() as i32 {
|
||||
i16::min_value()
|
||||
} else {
|
||||
exp.try_into().unwrap()
|
||||
};
|
||||
let res = x.scalbn(exp);
|
||||
this.write_scalar(Scalar::from_f64(res), dest)?;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue