How to print f80 and f128?

I wrote some functions that prints out pi as f64, f80, and f128, but there seems to be no support for the higher-precision types at the moment:

const std = @import("std");

pub fn printPi64() void {
    std.debug.print("pi = {d}\n", .{@as(f64, std.math.pi)});
}

pub fn printPi80() void {
    std.debug.print("pi = {d}\n", .{@as(f80, std.math.pi)});
}

pub fn printPi128() void {
    std.debug.print("pi = {d}\n", .{@as(f128, std.math.pi)});
}
/home/cleong/.zvm/master/lib/std/fmt.zig:1243:22: error: expected type 'f64', found 'f80'

The replacing {d} with {e} allows the code to compile but the result is truncated to f64.

That is a known, open, issue

IIRC the algorithm used for doing the printing is f64 internally.

1 Like