@@ -1020,7 +1020,7 @@ test "mul large" {
1020
1020
// Generate a number that's large enough to cross the thresholds for the use
1021
1021
// of subquadratic algorithms
1022
1022
for (a .limbs ) | * p | {
1023
- p .* = std . math . maxInt (Limb );
1023
+ p .* = maxInt (Limb );
1024
1024
}
1025
1025
a .setMetadata (true , 50 );
1026
1026
@@ -1104,7 +1104,7 @@ test "mulWrap large" {
1104
1104
// Generate a number that's large enough to cross the thresholds for the use
1105
1105
// of subquadratic algorithms
1106
1106
for (a .limbs ) | * p | {
1107
- p .* = std . math . maxInt (Limb );
1107
+ p .* = maxInt (Limb );
1108
1108
}
1109
1109
a .setMetadata (true , 50 );
1110
1110
@@ -1961,23 +1961,78 @@ test "truncate to mutable with fewer limbs" {
1961
1961
.positive = undefined ,
1962
1962
};
1963
1963
res .truncate (.{ .positive = true , .limbs = &.{ 0 , 1 } }, .unsigned , @bitSizeOf (Limb ));
1964
- try testing .expect (res .eqlZero () );
1964
+ try testing .expect (res .positive and res . len == 1 and res . limbs [ 0 ] == 0 );
1965
1965
res .truncate (.{ .positive = true , .limbs = &.{ 0 , 1 } }, .signed , @bitSizeOf (Limb ));
1966
- try testing .expect (res .eqlZero () );
1966
+ try testing .expect (res .positive and res . len == 1 and res . limbs [ 0 ] == 0 );
1967
1967
res .truncate (.{ .positive = false , .limbs = &.{ 0 , 1 } }, .unsigned , @bitSizeOf (Limb ));
1968
- try testing .expect (res .eqlZero () );
1968
+ try testing .expect (res .positive and res . len == 1 and res . limbs [ 0 ] == 0 );
1969
1969
res .truncate (.{ .positive = false , .limbs = &.{ 0 , 1 } }, .signed , @bitSizeOf (Limb ));
1970
- try testing .expect (res .eqlZero () );
1971
- res .truncate (.{ .positive = true , .limbs = &.{ std . math . maxInt (Limb ), 1 } }, .unsigned , @bitSizeOf (Limb ));
1972
- try testing .expect (res .toConst ().orderAgainstScalar (std . math . maxInt (Limb )).compare (.eq ));
1973
- res .truncate (.{ .positive = true , .limbs = &.{ std . math . maxInt (Limb ), 1 } }, .signed , @bitSizeOf (Limb ));
1970
+ try testing .expect (res .positive and res . len == 1 and res . limbs [ 0 ] == 0 );
1971
+ res .truncate (.{ .positive = true , .limbs = &.{ maxInt (Limb ), 1 } }, .unsigned , @bitSizeOf (Limb ));
1972
+ try testing .expect (res .toConst ().orderAgainstScalar (maxInt (Limb )).compare (.eq ));
1973
+ res .truncate (.{ .positive = true , .limbs = &.{ maxInt (Limb ), 1 } }, .signed , @bitSizeOf (Limb ));
1974
1974
try testing .expect (res .toConst ().orderAgainstScalar (-1 ).compare (.eq ));
1975
- res .truncate (.{ .positive = false , .limbs = &.{ std . math . maxInt (Limb ), 1 } }, .unsigned , @bitSizeOf (Limb ));
1975
+ res .truncate (.{ .positive = false , .limbs = &.{ maxInt (Limb ), 1 } }, .unsigned , @bitSizeOf (Limb ));
1976
1976
try testing .expect (res .toConst ().orderAgainstScalar (1 ).compare (.eq ));
1977
- res .truncate (.{ .positive = false , .limbs = &.{ std . math . maxInt (Limb ), 1 } }, .signed , @bitSizeOf (Limb ));
1977
+ res .truncate (.{ .positive = false , .limbs = &.{ maxInt (Limb ), 1 } }, .signed , @bitSizeOf (Limb ));
1978
1978
try testing .expect (res .toConst ().orderAgainstScalar (1 ).compare (.eq ));
1979
1979
}
1980
1980
1981
+ test "truncate value that normalizes after being masked" {
1982
+ var res_limbs : [2 ]Limb = undefined ;
1983
+ var res : Mutable = .{
1984
+ .limbs = & res_limbs ,
1985
+ .len = undefined ,
1986
+ .positive = undefined ,
1987
+ };
1988
+ res .truncate (.{ .positive = true , .limbs = &.{ 0 , 2 } }, .signed , 1 + @bitSizeOf (Limb ));
1989
+ try testing .expect (res .positive and res .len == 1 and res .limbs [0 ] == 0 );
1990
+ res .truncate (.{ .positive = true , .limbs = &.{ 1 , 2 } }, .signed , 1 + @bitSizeOf (Limb ));
1991
+ try testing .expect (res .toConst ().orderAgainstScalar (1 ).compare (.eq ));
1992
+ }
1993
+
1994
+ test "truncate to zero" {
1995
+ var res_limbs : [1 ]Limb = undefined ;
1996
+ var res : Mutable = .{
1997
+ .limbs = & res_limbs ,
1998
+ .len = undefined ,
1999
+ .positive = undefined ,
2000
+ };
2001
+ res .truncate (.{ .positive = true , .limbs = &.{0 } }, .signed , @bitSizeOf (Limb ));
2002
+ try testing .expect (res .positive and res .len == 1 and res .limbs [0 ] == 0 );
2003
+ res .truncate (.{ .positive = false , .limbs = &.{0 } }, .signed , @bitSizeOf (Limb ));
2004
+ try testing .expect (res .positive and res .len == 1 and res .limbs [0 ] == 0 );
2005
+ res .truncate (.{ .positive = true , .limbs = &.{0 } }, .unsigned , @bitSizeOf (Limb ));
2006
+ try testing .expect (res .positive and res .len == 1 and res .limbs [0 ] == 0 );
2007
+ res .truncate (.{ .positive = false , .limbs = &.{0 } }, .unsigned , @bitSizeOf (Limb ));
2008
+ try testing .expect (res .positive and res .len == 1 and res .limbs [0 ] == 0 );
2009
+ res .truncate (.{ .positive = true , .limbs = &.{ 0 , 1 } }, .signed , @bitSizeOf (Limb ));
2010
+ try testing .expect (res .positive and res .len == 1 and res .limbs [0 ] == 0 );
2011
+ res .truncate (.{ .positive = false , .limbs = &.{ 0 , 1 } }, .signed , @bitSizeOf (Limb ));
2012
+ try testing .expect (res .positive and res .len == 1 and res .limbs [0 ] == 0 );
2013
+ res .truncate (.{ .positive = true , .limbs = &.{ 0 , 1 } }, .unsigned , @bitSizeOf (Limb ));
2014
+ try testing .expect (res .positive and res .len == 1 and res .limbs [0 ] == 0 );
2015
+ res .truncate (.{ .positive = false , .limbs = &.{ 0 , 1 } }, .unsigned , @bitSizeOf (Limb ));
2016
+ try testing .expect (res .positive and res .len == 1 and res .limbs [0 ] == 0 );
2017
+ }
2018
+
2019
+ test "truncate to minimum signed integer" {
2020
+ var res_limbs : [1 ]Limb = undefined ;
2021
+ var res : Mutable = .{
2022
+ .limbs = & res_limbs ,
2023
+ .len = undefined ,
2024
+ .positive = undefined ,
2025
+ };
2026
+ res .truncate (.{ .positive = true , .limbs = &.{1 << @bitSizeOf (Limb ) - 1 } }, .signed , @bitSizeOf (Limb ));
2027
+ try testing .expect (res .toConst ().orderAgainstScalar (-1 << @bitSizeOf (Limb ) - 1 ).compare (.eq ));
2028
+ res .truncate (.{ .positive = false , .limbs = &.{1 << @bitSizeOf (Limb ) - 1 } }, .signed , @bitSizeOf (Limb ));
2029
+ try testing .expect (res .toConst ().orderAgainstScalar (-1 << @bitSizeOf (Limb ) - 1 ).compare (.eq ));
2030
+ res .truncate (.{ .positive = true , .limbs = &.{1 << @bitSizeOf (Limb ) - 1 } }, .unsigned , @bitSizeOf (Limb ));
2031
+ try testing .expect (res .toConst ().orderAgainstScalar (1 << @bitSizeOf (Limb ) - 1 ).compare (.eq ));
2032
+ res .truncate (.{ .positive = false , .limbs = &.{1 << @bitSizeOf (Limb ) - 1 } }, .unsigned , @bitSizeOf (Limb ));
2033
+ try testing .expect (res .toConst ().orderAgainstScalar (1 << @bitSizeOf (Limb ) - 1 ).compare (.eq ));
2034
+ }
2035
+
1981
2036
test "saturate single signed positive" {
1982
2037
var a = try Managed .initSet (testing .allocator , 0xBBBB_BBBB );
1983
2038
defer a .deinit ();
0 commit comments