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
Your example is obviously trivial, but if you can express your number in terms of sqrt(2) or sqrt(π), you may be able to build it with the standard consts: std::f64::consts - Rust
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.