如何在Rust中使用十六进制表示法指定浮点数文字? [英] How to specify a floating point number literal using hexadecimal notation In Rust?
本文介绍了如何在Rust中使用十六进制表示法指定浮点数文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在实现 xoshiro256 ++ ,并且能够生成伪随机的64位无符号整数.下一个挑战是要从u64的PRNG的单位间隔中产生均匀的双打.
I'm implementing xoshiro256++ and I'm able to generate pseudo-random 64-bit unsigned integers. The next challenge is generating uniform doubles in the unit interval from the PRNGs u64's.
应使用表达式将64位无符号整数x转换为64位double
a 64-bit unsigned integer x should be converted to a 64-bit double using the expression
(x >> 11) * 0x1.0p-53
人们将如何在Rust中对此进行评估?尝试此操作时,出现编译错误:
How would one evaluate this in Rust? On trying this I get the compile error:
error: hexadecimal float literal is not supported
--> src/main.rs:30:56
|
30 | f64::from_bits((x >> 11).wrapping_mul(0x1.0p-53))
| ^^^^^
推荐答案
您可以使用 hexf板条箱:
#[macro_use]
extern crate hexf;
fn main() {
let v = hexf64!("0x1.0p-53");
println!("{}", v);
}
另请参阅:
这篇关于如何在Rust中使用十六进制表示法指定浮点数文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文