-
Notifications
You must be signed in to change notification settings - Fork 3
Float
Chung Leong edited this page Feb 11, 2024
·
6 revisions
Floats are 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 JavaScript as number
. Because number
is defined by ECMA to be a double-precision float, returning f80
and f128
to JavaScript 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;
}
import { getPi64, getPi80, getPi128 } from './float-example-1.zig';
console.log(getPi80() === getPi64());
console.log(getPi128() === getPi64());
true
true