zig/lib/std/special/compiler_rt/floatunditf.zig
Andrew Kelley d29871977f remove redundant license headers from zig standard library
We already have a LICENSE file that covers the Zig Standard Library. We
no longer need to remind everyone that the license is MIT in every single
file.

Previously this was introduced to clarify the situation for a fork of
Zig that made Zig's LICENSE file harder to find, and replaced it with
their own license that required annual payments to their company.
However that fork now appears to be dead. So there is no need to
reinforce the copyright notice in every single file.
2021-08-24 12:25:09 -07:00

28 lines
784 B
Zig

const builtin = @import("builtin");
const is_test = builtin.is_test;
const std = @import("std");
pub fn __floatunditf(a: u64) callconv(.C) f128 {
@setRuntimeSafety(is_test);
if (a == 0) {
return 0;
}
const mantissa_bits = std.math.floatMantissaBits(f128);
const exponent_bits = std.math.floatExponentBits(f128);
const exponent_bias = (1 << (exponent_bits - 1)) - 1;
const implicit_bit = 1 << mantissa_bits;
const exp: u128 = (64 - 1) - @clz(u64, a);
const shift: u7 = mantissa_bits - @intCast(u7, exp);
var result: u128 = (@intCast(u128, a) << shift) ^ implicit_bit;
result += (exp + exponent_bias) << mantissa_bits;
return @bitCast(f128, result);
}
test "import floatunditf" {
_ = @import("floatunditf_test.zig");
}