#Safely power a F64?
19 messages · Page 1 of 1 (latest)
I guess you can call is_infinite() to check
Alright
It can’t get overloaded
Rust doesn’t have method overloading
if you have a type, and you know it’s an f64, .powi will always call the same function
no matter the context
Looks like f32/f64 don't have any checked_ functions, which is a little weird
oh, you meant over_flow_ 😄
whaaat
this seems like a big oversight
or maybe we're missing something which i really hope is what's happening
I’m not really sure floats have overflow in the same way integers do
Floats just converge to infinity iirc
So the only real "overflow check" you’d do would be like rust fn checked_powi(f: f64, pow: u32) -> Option<f64> { let power = f.powi(pow); if power.is_infinite() { None } else { Some(power) } }
Yeah it would just be that, which while not as crucial as the integer ones, because those can't be emulated, I think it would be good to have a consistent language for this kind of stuff
Sure, I think it’s just an effect of floats not really having a concept of checking
And the applications using them not actually needing it
processors actually do have flags that can turn e.g. NaN creation (not sure what else; couldn't find docs quickly) into a trap/interrupt; the problem is that very few languages let you actually enable that in a way that isn't UB-or-implementation-defined, because the CPU having state that changes what instructions do is inconvenient to deal with
And people not usually caring about numbers big enough to make an f64 go infinite