【发布时间】:2014-12-28 13:38:47
【问题描述】:
我有以下代码行,我希望它可以正常工作:
const pi_n4th_root : f32 = Float::pi().powf(-1.0/4.0);
但它会产生以下错误:
f.rs:7:28: 7:54 error: the type of this value must be known in this context
f.rs:7 const pi_n4th_root : f32 = Float::pi().powf(-1.0/4.0);
^~~~~~~~~~~~~~~~~~~~~~~~~~
我尝试添加所有可以添加的类型注释:
const pi_n4th_root : f32 = (Float::pi() as f32).powf(-1.0/4.0 as f32) as f32;
但它仍然失败并出现同样的错误:
f.rs:7:30: 9:55 error: the type of this value must be known in this context
f.rs:7 const pi_m4th_root : f32 = (Float::pi::<f32>() as f32).powf(-1.0/4.0 as f32) as f32;
^~~~~~~~~~~~~~~~~~~~~~~~~
似乎我需要以某种方式指定为 f32 类型调用 Float::pi,但该怎么做?
【问题讨论】:
标签: rust type-inference