blob: c1190ebd70d84b1dcd866cbe828abccaa70467e9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
// Note that all the methods and functions are duplicated across the formats,
// with different constants substituted to compute the "all ones"
// of the exponents and the bitmask for the significand MSB.
// ieee754.pk and ieee754-test.pk are intended for upstream poke/pickles/
// but left here until they can be properly upstreamed.
type IEEE754_binary16 = struct int<16> {
uint<1> sign;
uint<5> exp;
uint<10> frac; // aka significand aka mantissa
fun exp_all_ones = uint<1>: {
return 0x1f == exp;
}
method is_nan = uint<1>: {
// if msb of frac is 1: signaling
// if msb of frac is 0: quiet NaN
return 0 != frac && exp_all_ones();
}
method is_snan = uint<1>: {
return exp_all_ones() && (0x200 & frac);
}
method is_qnan = uint<1>: {
return is_nan() && !(0x200 & frac);
}
method is_inf = uint<1>: {
return 0 == frac && exp_all_ones();
}
};
type IEEE754_binary32 = struct int<32> {
uint<1> sign;
uint<8> exp;
uint<23> frac; // aka significand aka mantissa
fun exp_all_ones = uint<1>: {
return 0xff == exp;
}
method is_nan = uint<1>: {
// if msb of frac is 1: signaling
// if msb of frac is 0: quiet NaN
return 0 != frac && exp_all_ones();
}
method is_snan = uint<1>: {
return exp_all_ones() && (0x400000 & frac);
}
method is_qnan = uint<1>: {
return is_nan() && !(0x400000 & frac);
}
method is_inf = uint<1>: {
return 0 == frac && exp_all_ones();
}
};
type IEEE754_binary64 = struct int<64> {
uint<1> sign;
uint<11> exp;
uint<52> frac; // aka significand aka mantissa
fun exp_all_ones = uint<1>: {
return 0x7ff == exp;
}
method is_nan = uint<1>: {
// if msb of frac is 1: signaling
// if msb of frac is 0: quiet NaN
return 0 != frac && exp_all_ones();
}
method is_snan = uint<1>: {
return exp_all_ones() && (0x4000000000000 & frac);
}
method is_qnan = uint<1>: {
return is_nan() && !(0x4000000000000 & frac);
}
method is_inf = uint<1>: {
return 0 == frac && exp_all_ones();
}
};
type Float_16 = IEEE754_binary16;
type Float_32 = IEEE754_binary32;
type Float_64 = IEEE754_binary64;
|
.
.
If you have reason to request commit access to one of these repositories please
.
You may also send me patches by email.