docs

你正在阅读 v0.1.0 的文档。Nabi 0.1.0 已不再提供支持。 最新版本:v0.1.3 →

本页尚未翻译,以下为英文原文。

#E0144: integer raised to a negative power

b ** e on an integer base gives an integer, so the exponent is a u32: 2 ** -1 would be 0.5, which no integer holds. Raise a float (2.0 ** -1.0, or (x as f64) ** -1.0), or keep the exponent non-negative.

nabi
let half = 2 ** -1;
error[E0144]: `i64` to a negative power is a fraction, not an integer
  --> main.nabi:1:17
   |
 1 | let half = 2 ** -1;
   |                 ^^
   |
   = help: raise a float instead: `2.0 ** -1.0`

Raise a float:

nabi
let half = 2.0 ** -1.0;
let n: i32 = 4;
println(f"{half} {(n as f64) ** -1.0}");
0.5 0.25

Related: E0040 mismatched types

Found a mistake? Edit this page on GitHub. Last updated