The following constants are required globally in my code:
const A: f64 = 1.0/(2.0_f64.sqrt());
const B: f64 = 1.0/10.0_f64.sqrt();
const C: f64 = 1.0/42.0_f64.sqrt();
Rust should support this by default. It is not efficient to hard code the sqrt of a number before it can be assigned to a const variable.
The following sample code throws an error
const A: f64 = 1.0/4.0_f64.sqrt();
fn main() {
println!("{}", A);
}
error[E0015]: calls in constants are limited to tuple structs and tuple variants
–> src\main.rs:3:20
|
3 | const A: f64 = 1.0/4.0_f64.sqrt();
| ^^^^^^^^^^^^^^
|
note: a limited form of compile-time function evaluation is available on a nightly compiler via `const fn`
–> src\main.rs:3:20