float
type float
Source: compiler/src/builtin_docs/types.hy A 64-bit IEEE-754 floating-point number.
Literals need digits on both sides of the point (1.0, 3.14, not 1.
or .5); there is no exponent form. Arithmetic follows IEEE-754 and
never panics: 1.0 / 0.0 is infinity and invalid operations give NaN.
% is the remainder with the sign of the left operand, like the rem
function.
Casts with as: float as int truncates toward zero (NaN becomes 0,
infinities saturate). There is no direct cast between float and byte;
go through int. Mixing int and float in one operator is a type error.
float implements Num, Ord, Eq and Show, but not Integral.
Math functions such as sqrt and sin are in prelude::math.
Examples#
use tests::assert;
let x = 2.5;
assert!(x * 2.0 == 5.0);
assert!(7.5 % 2.0 == 1.5);
assert!(-2.7 as int == -2);
assert!(3 as float + x == 5.5);
assert!(1.0 / 0.0 > 1000000.0);
assert!(show(x) == "2.5");