@@ -4,7 +4,7 @@ const std = @import("std");
4
4
pub const i32p10 = FixedPoint (32 , 1024 );
5
5
6
6
/// medium range, medium precision fixed point value between -32000 and +32000, with a precision of roughly 0.000015
7
- pub const i32p64 = FixedPoint (32 , 65536 );
7
+ pub const i32p16 = FixedPoint (32 , 65536 );
8
8
9
9
/// high precision fixed point with i32 integer range and a precision of roughly 0.00000000025
10
10
pub const i64p32 = FixedPoint (64 , 1 << 32 );
@@ -16,10 +16,10 @@ pub fn FixedPoint(comptime bits: comptime_int, comptime scaling: comptime_int) t
16
16
if (scaling < 1 )
17
17
@compileError ("scaling must be a positive, non-zero integer!" );
18
18
const BaseInt = @Type (.{
19
- .Int = .{ .bits = bits , .signedness = .signed },
19
+ .int = .{ .bits = bits , .signedness = .signed },
20
20
});
21
21
const BaseIntUnsigned = @Type (.{
22
- .Int = .{ .bits = bits - 1 , .signedness = .unsigned },
22
+ .int = .{ .bits = bits - 1 , .signedness = .unsigned },
23
23
});
24
24
if (scaling > std .math .maxInt (BaseInt ))
25
25
@compileError (std .fmt .comptimePrint ("scaling must be less than {}" , .{std .math .maxInt (BaseInt )}));
@@ -32,11 +32,11 @@ pub fn FixedPoint(comptime bits: comptime_int, comptime scaling: comptime_int) t
32
32
pub const Int = BaseInt ;
33
33
34
34
pub const Int2 = @Type (.{
35
- .Int = .{ .bits = 2 * bits , .signedness = .signed },
35
+ .int = .{ .bits = 2 * bits , .signedness = .signed },
36
36
});
37
37
38
38
pub const IntPart = @Type (.{
39
- .Int = .{ .bits = bits - scaling_bits_max , .signedness = .signed },
39
+ .int = .{ .bits = bits - scaling_bits_max , .signedness = .signed },
40
40
});
41
41
42
42
pub const precision = 2.0 / @as (comptime_float , scaling );
@@ -58,7 +58,7 @@ pub fn FixedPoint(comptime bits: comptime_int, comptime scaling: comptime_int) t
58
58
59
59
pub fn toFloat (v : F , comptime T : type ) T {
60
60
// std.debug.print("toFloat({}, {})\n", .{ Int, v.raw });
61
- _ = @typeInfo (T ).Float ;
61
+ _ = @typeInfo (T ).float ;
62
62
return @as (T , @floatFromInt (v .raw )) / scaling ;
63
63
}
64
64
@@ -169,7 +169,7 @@ pub fn FixedPoint(comptime bits: comptime_int, comptime scaling: comptime_int) t
169
169
170
170
test {
171
171
_ = TestSuite (i32p10 );
172
- _ = TestSuite (i32p64 );
172
+ _ = TestSuite (i32p16 );
173
173
_ = TestSuite (i64p32 );
174
174
_ = TestSuite (FixedPoint (32 , 1000 ));
175
175
_ = TestSuite (FixedPoint (64 , 1000 ));
0 commit comments