Type ‣ Float ᴾᴴᴾ - chung-leong/zigar GitHub Wiki

JavaScript | PHP


A float is a data type used to store numbers with decimal parts. There are five types in Zig: f16 (half-precision), f32 (single-precision), f64 (double-precision), f80 (extended precision), and f128 (quadruple-precision). They are all represented in PHP as number. Because PHP only supports double-precision float, returning f80 and f128 will result in loss in precision.

const std = @import("std");

pub fn getPi64() f64 {
    return std.math.pi;
}

pub fn getPi80() f80 {
    return std.math.pi;
}

pub fn getPi128() f128 {
    return std.math.pi;
}
<?php

$m = zigar_use(__DIR__ . '/float-example-1.zig');

debug_zval_dump($m->getPi80() === $m->getPi64()); 
debug_zval_dump($m->getPi128() === $m->getPi64());
bool(true)
bool(true)

Types | Comptime float