Floats
- - IEEE-754-2008 binary16
f32
- IEEE-754-2008 binary32f64
- IEEE-754-2008 binary64c_longdouble
- matcheslong double
for the target C ABI
Float literals have type which is guaranteed to have the same precision and operations of the largest other floating point type, which is f128
.
Float literals implicitly cast to any floating point type, and to any type when there is no fractional component.
const std = @import("std");
const inf = std.math.inf(f32);
const negative_inf = -std.math.inf(f64);
Floating Point Operations
By default floating point operations use Strict
mode, but you can switch to Optimized
mode on a per-block basis:
foo.zig
$ zig build-obj foo.zig --release-fast
float_mode.zig
$ zig build-exe float_mode.zig --object foo.o
$ ./float_mode
strict = 9.765625e-04
See also: