Floats

    • - IEEE-754-2008 binary16
    • f32 - IEEE-754-2008 binary32
    • f64 - IEEE-754-2008 binary64
    • c_longdouble - matches long 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 to any floating point type, and to any integer type when there is no fractional component.

    1. const std = @import("std");
    2. const inf = std.math.inf(f32);
    3. 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

    1. $ zig build-obj foo.zig --release-fast

    float_mode.zig

    1. $ zig build-exe float_mode.zig --object foo.o
    2. $ ./float_mode
    3. strict = 9.765625e-04

    See also: