Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BigInteger type #10750

Open
wants to merge 147 commits into
base: development
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
ac9648b
Add BigInteger type
flashultra Jul 7, 2022
d502605
Add BigInt test and allow unit package
flashultra Jul 10, 2022
b6ebec0
Merge branch 'HaxeFoundation:development' into development
flashultra Jul 10, 2022
6aa9204
Add abs,pow,modPow,isProbablePrime,getLowestSetBit,bitLength methods
flashultra Jul 16, 2022
baa9010
Merge branch 'development' of https://github.com/flashultra/haxe into…
flashultra Jul 16, 2022
17a09e6
Add missing tests and counting of trailing zeros
flashultra Jul 16, 2022
60de60d
Run tests for BigInt
flashultra Jul 16, 2022
e2fdb58
Add missing const
flashultra Jul 16, 2022
65bd87c
Fiexes for Int32 ( javascript)
flashultra Jul 17, 2022
2979ee9
More fixes for Int32
flashultra Jul 18, 2022
e0b0218
Add trace for macro crash
flashultra Jul 18, 2022
b63329f
Fix missing ;
flashultra Jul 18, 2022
91688ac
Fix macro test
flashultra Jul 18, 2022
4da8487
Remove macrotest crash
flashultra Jul 18, 2022
99adeca
Fix Int32 (python)
flashultra Jul 19, 2022
f7c405f
More fixes
flashultra Jul 19, 2022
c5dfc60
More fixes for python
flashultra Jul 19, 2022
2dca9df
more fixes
flashultra Jul 19, 2022
4cf361f
Merge branch 'HaxeFoundation:development' into development
flashultra Jul 22, 2022
984a696
Fix for Python target
flashultra Jul 22, 2022
2f45acc
Correct test for mutable bigint
flashultra Jul 22, 2022
39e31fa
Add method to create BigInt from bytes
flashultra Jul 24, 2022
7b5b70b
Add auto convert from String
flashultra Jul 25, 2022
4648790
Add greater common divisor (gcd) of two BigInt values
flashultra Jul 25, 2022
45980ef
Add lcm,min,max,nextprobableprime methods
flashultra Jul 26, 2022
1e8051d
Merge branch 'HaxeFoundation:development' into development
flashultra Jul 26, 2022
4f99754
Add method to create random BigInt
flashultra Jul 26, 2022
d2916d7
Add test for random and small fixes
flashultra Jul 26, 2022
e6fe7c5
More random methods and some fixes
flashultra Jul 28, 2022
ce5378d
Fix pow bug
flashultra Jul 28, 2022
76a883f
Add test for random prime and random in range + prime fix
flashultra Jul 28, 2022
57927b8
Remove trace(..)
flashultra Jul 28, 2022
39252d4
Fix test
flashultra Jul 28, 2022
70fbb33
Fix unsigned compare for randomInRange
flashultra Jul 29, 2022
f2de369
Fix for randomInRange
flashultra Jul 29, 2022
8bf946a
Hope dies last
flashultra Jul 29, 2022
2866088
Fix for JS
flashultra Jul 29, 2022
c26f036
Better check for sign
flashultra Jul 30, 2022
6e8f2d8
Thanks to cbatson
flashultra Aug 1, 2022
bec8abe
Add modInverse method
flashultra Aug 20, 2022
f4d5e6d
Add bitcount(),isPositive,isEven and isOdd methods
flashultra Aug 21, 2022
a0e1598
Add testBit() method
flashultra Aug 21, 2022
3c5c0a2
Add tests for modInverse,isPositive,isEven,isOdd, testBit, bitCount
flashultra Aug 21, 2022
157c0e2
Fix bitcount
flashultra Aug 21, 2022
8bd592c
Try to fix bitCount()
flashultra Aug 21, 2022
3eb46e4
Debug cpp (couldn't repeat)
flashultra Aug 22, 2022
880f710
Fix debug
flashultra Aug 22, 2022
b15c9f0
Debug
flashultra Aug 22, 2022
edbb6d4
[cpp] Fix bitCount()
flashultra Aug 22, 2022
257e751
Add square() and Karatsuba multiplication
flashultra Sep 3, 2022
326d026
Add test for Karatsuba square
flashultra Sep 3, 2022
5273e4c
Merge branch 'HaxeFoundation:development' into development
flashultra Dec 13, 2022
2aebe42
Merge branch 'HaxeFoundation:development' into development
flashultra Dec 13, 2022
197ab84
Merge branch 'HaxeFoundation:development' into development
flashultra Dec 13, 2022
8b65d53
Add divMod and hashCode functions.Auto convert to string
flashultra Jan 18, 2023
b030dec
Fix last commit.
flashultra Jan 18, 2023
21900e6
Fix overflow behaviour
flashultra Jan 18, 2023
39038bf
Add negative base for modInverse
flashultra Jan 26, 2023
de89828
Add OR and AND (bigint) operations
flashultra Jan 31, 2023
786cbec
Fix for negative numbers
flashultra Jan 31, 2023
d1a15f8
Correct OR for bigint
flashultra Jan 31, 2023
3733409
For OR small optimization
flashultra Jan 31, 2023
aec1211
Add XOR and NOT bitwise operators
flashultra Jan 31, 2023
e76288c
Add bit operations and powerOfTwo method
flashultra Feb 26, 2023
c4fe08c
Test bit for negative numbers
flashultra Feb 26, 2023
b877aa9
Use enum abstract for exception. Reformat the code
flashultra Mar 1, 2023
5fa6c53
Add missing tests
flashultra Mar 1, 2023
b7626bc
Temp fix for BigIntException
flashultra Mar 1, 2023
f9417ea
Fix for BigIntExceptions
flashultra Mar 2, 2023
3ab6538
Fix BigIntExceptions test
flashultra Mar 2, 2023
3b87a7e
Fix tests for String conversion
flashultra Mar 2, 2023
1245ce8
Temp fix for flipBit (python)
flashultra Mar 2, 2023
704100c
Add @:noDoc and @:noCompletion .Fix for BigIntException and tests
flashultra Mar 4, 2023
b4faf0a
Change var NEGATIVE_ONE to MINUS_ONE
flashultra Mar 4, 2023
f1f1e11
New implementation for BigIntException class
flashultra Mar 4, 2023
e4c22e6
Remove memory limit for PHP test
flashultra Mar 22, 2023
ec9646c
Fix for php test
flashultra Mar 23, 2023
5177449
Add from/to different base
flashultra Apr 6, 2023
0a7500c
Remove trace()
flashultra Apr 6, 2023
b664dcc
Fix for toString()
flashultra Apr 6, 2023
611d36f
Merge branch 'development' of https://github.com/HaxeFoundation/haxe …
flashultra Dec 26, 2023
fab6b83
Merge branch 'development' of https://github.com/HaxeFoundation/haxe …
flashultra Jan 6, 2024
5da8f75
Add Montgomery and Barrett reduction for modPow
flashultra Jan 6, 2024
0d6f584
Add bitlen()
flashultra Jan 6, 2024
4cb131d
Fix typo
flashultra Jan 6, 2024
2173c8a
Add compareMonty() and subtractMonty()
flashultra Jan 7, 2024
9293500
Change millerRabin().Fix compareMonty()
flashultra Jan 7, 2024
0011ee5
Merge branch 'HaxeFoundation:development' into development
flashultra Jan 7, 2024
4a1b149
Prime check for small numbers
flashultra Jan 7, 2024
d8d1b3d
Merge branch 'development' of https://github.com/flashultra/haxe into…
flashultra Jan 7, 2024
bffa60e
Debug Lua
flashultra Jan 8, 2024
e4faadc
Always init m_data
flashultra Jan 8, 2024
79e5779
Merge branch 'HaxeFoundation:development' into development
flashultra Dec 10, 2024
7bc65dc
Trigger GitHub actions
flashultra Dec 13, 2024
502f950
Debug BigIntRandomPrime [php,python]
flashultra Dec 13, 2024
8849e8b
Fix syntax err
flashultra Dec 13, 2024
422ec2d
Lua test - modInverse
flashultra Dec 13, 2024
5051966
Is toString() the problem ?
flashultra Dec 13, 2024
7452b85
Debug Lua
flashultra Dec 13, 2024
4448668
Debug compare()
flashultra Dec 13, 2024
274a2fd
Is the unsigned shift the problem ?
flashultra Dec 13, 2024
bddad70
Test sign() Lua
flashultra Dec 14, 2024
7c59327
Lua clampInt32 for compareInt()
flashultra Dec 14, 2024
71a8da6
Check compare() - Lua
flashultra Dec 14, 2024
9b376fc
Clamp left shift - Lua
flashultra Dec 14, 2024
8dcf4e5
[lua] Shift left doesn't work correctly
flashultra Dec 14, 2024
f851be7
Test left shift for Lua
flashultra Dec 14, 2024
ffec547
Sign test - Lua
flashultra Dec 14, 2024
4bbf648
Clamp lshift too, because -1 << 1 is 4294967294, but should be -2
flashultra Dec 14, 2024
6b634a2
Check for nil
flashultra Dec 14, 2024
0589e3d
What is nil ?
flashultra Dec 14, 2024
ad29bc8
Check testPrimeNumber
flashultra Dec 14, 2024
dee19e9
Lua nil debug
flashultra Dec 14, 2024
d2bbbcd
Debug
flashultra Dec 14, 2024
1c418e5
Debug Lua
flashultra Dec 14, 2024
3c19c45
Dbg Lua
flashultra Dec 14, 2024
eb9bd4b
Debug
flashultra Dec 14, 2024
fd76eb9
Remove debug ( failed)
flashultra Dec 14, 2024
975ab17
Last chance Lua
flashultra Dec 14, 2024
e91d2d2
Init m_count
flashultra Dec 14, 2024
8fbfcdb
Set m_data to null
flashultra Dec 14, 2024
83a3ae9
Debug
flashultra Dec 14, 2024
4a785f3
Debug
flashultra Dec 14, 2024
965a274
Debug
flashultra Dec 14, 2024
380e066
How num is null?
flashultra Dec 15, 2024
27e52a9
Trigger GitHub actions
flashultra Dec 16, 2024
6596762
Spooky compare call
flashultra Dec 16, 2024
008f6b0
wheel of fortune
flashultra Dec 16, 2024
abf4385
Check if this it the init poblem for Lua
flashultra Dec 16, 2024
5ee77da
Remove trace() and workaround
flashultra Dec 16, 2024
194cd6f
Remove Lua fix
flashultra Dec 17, 2024
df9906f
Merge branch 'HaxeFoundation:development' into development
flashultra Dec 17, 2024
bdf1e32
Add test for Python
flashultra Dec 17, 2024
ebfc736
Check why Python failed
flashultra Dec 17, 2024
903db1e
Check Python
flashultra Dec 17, 2024
428232e
Fix Python target
flashultra Dec 18, 2024
7778f19
Fix for Neko
flashultra Dec 19, 2024
1fd473b
Fix Neko II
flashultra Dec 19, 2024
3696602
Remove prime test for Lua and Cppia
flashultra Dec 20, 2024
3ec3f61
Fix for Cppia (see issue #11897)
flashultra Dec 20, 2024
4bf7251
Reorder const
flashultra Dec 20, 2024
542d1bd
Fix typo
flashultra Dec 20, 2024
51eaff1
Reorder static var
flashultra Dec 20, 2024
65f0dd7
Workaround Cppia
flashultra Dec 22, 2024
ab17d83
Fix Cppia II
flashultra Dec 22, 2024
432a3d1
Give up
flashultra Dec 22, 2024
c188704
I won't never give up, no, never give up, no
flashultra Dec 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add @:noDoc and @:noCompletion .Fix for BigIntException and tests
flashultra committed Mar 4, 2023
commit 704100c4a8c57ed417dfc3c2bcf688dae77ca15b
102 changes: 51 additions & 51 deletions std/haxe/math/bigint/BigInt.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C)2005-2022 Haxe Foundation
* Copyright (C)2005-2023 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -219,227 +219,227 @@ abstract BigInt(BigInt_) {
// * BigInt <binOp> BigInt
// * BigInt <binOp> MutableBigInt
// Unary negation
@:op(-A) @:noCompletion public static inline function negate_(a:BigInt):BigInt {
@:op(-A) @:noCompletion @:noDoc public static inline function negate_(a:BigInt):BigInt {
return new BigInt(BigInt_.negate1(a));
}

// Binary equality
@:op(A == B) @:noCompletion public static inline function eqInt_(a:BigInt, b:Int):Bool {
@:op(A == B) @:noCompletion @:noDoc public static inline function eqInt_(a:BigInt, b:Int):Bool {
return BigInt_.equals2Int(a, b);
}

@:op(A == B) @:noCompletion public static inline function eq_(a:BigInt, b:BigInt):Bool {
@:op(A == B) @:noCompletion @:noDoc public static inline function eq_(a:BigInt, b:BigInt):Bool {
return BigInt_.equals2(a, b);
}

@:op(A == B) @:noCompletion public static inline function eqMutable_(a:BigInt, b:MutableBigInt):Bool {
@:op(A == B) @:noCompletion @:noDoc public static inline function eqMutable_(a:BigInt, b:MutableBigInt):Bool {
return BigInt_.equals2(a, b);
}

// Binary inequality
@:op(A != B) @:noCompletion public static inline function ineqInt_(a:BigInt, b:Int):Bool {
@:op(A != B) @:noCompletion @:noDoc public static inline function ineqInt_(a:BigInt, b:Int):Bool {
return !BigInt_.equals2Int(a, b);
}

@:op(A != B) @:noCompletion public static inline function ineq_(a:BigInt, b:BigInt):Bool {
@:op(A != B) @:noCompletion @:noDoc public static inline function ineq_(a:BigInt, b:BigInt):Bool {
return !BigInt_.equals2(a, b);
}

@:op(A != B) @:noCompletion public static inline function ineqMutable_(a:BigInt, b:MutableBigInt):Bool {
@:op(A != B) @:noCompletion @:noDoc public static inline function ineqMutable_(a:BigInt, b:MutableBigInt):Bool {
return !BigInt_.equals2(a, b);
}

// Binary less than
@:op(A < B) @:noCompletion public static inline function ltInt_(a:BigInt, b:Int):Bool {
@:op(A < B) @:noCompletion @:noDoc public static inline function ltInt_(a:BigInt, b:Int):Bool {
return BigIntArithmetic.compareInt(a, b) < 0;
}

@:op(A < B) @:noCompletion public static inline function lt_(a:BigInt, b:BigInt):Bool {
@:op(A < B) @:noCompletion @:noDoc public static inline function lt_(a:BigInt, b:BigInt):Bool {
return BigIntArithmetic.compare(a, b) < 0;
}

@:op(A < B) @:noCompletion public static inline function ltMutable_(a:BigInt, b:MutableBigInt):Bool {
@:op(A < B) @:noCompletion @:noDoc public static inline function ltMutable_(a:BigInt, b:MutableBigInt):Bool {
return BigIntArithmetic.compare(a, b) < 0;
}

// Binary less than or equal
@:op(A <= B) @:noCompletion public static inline function lteInt_(a:BigInt, b:Int):Bool {
@:op(A <= B) @:noCompletion @:noDoc public static inline function lteInt_(a:BigInt, b:Int):Bool {
return BigIntArithmetic.compareInt(a, b) <= 0;
}

@:op(A <= B) @:noCompletion public static inline function lte_(a:BigInt, b:BigInt):Bool {
@:op(A <= B) @:noCompletion @:noDoc public static inline function lte_(a:BigInt, b:BigInt):Bool {
return BigIntArithmetic.compare(a, b) <= 0;
}

@:op(A <= B) @:noCompletion public static inline function lteMutable_(a:BigInt, b:MutableBigInt):Bool {
@:op(A <= B) @:noCompletion @:noDoc public static inline function lteMutable_(a:BigInt, b:MutableBigInt):Bool {
return BigIntArithmetic.compare(a, b) <= 0;
}

// Binary greater than
@:op(A > B) @:noCompletion public static inline function gtInt_(a:BigInt, b:Int):Bool {
@:op(A > B) @:noCompletion @:noDoc public static inline function gtInt_(a:BigInt, b:Int):Bool {
return BigIntArithmetic.compareInt(a, b) > 0;
}

@:op(A > B) @:noCompletion public static inline function gt_(a:BigInt, b:BigInt):Bool {
@:op(A > B) @:noCompletion @:noDoc public static inline function gt_(a:BigInt, b:BigInt):Bool {
return BigIntArithmetic.compare(a, b) > 0;
}

@:op(A > B) @:noCompletion public static inline function gtMutable_(a:BigInt, b:MutableBigInt):Bool {
@:op(A > B) @:noCompletion @:noDoc public static inline function gtMutable_(a:BigInt, b:MutableBigInt):Bool {
return BigIntArithmetic.compare(a, b) > 0;
}

// Binary greater than or equal
@:op(A >= B) @:noCompletion public static inline function gteInt_(a:BigInt, b:Int):Bool {
@:op(A >= B) @:noCompletion @:noDoc public static inline function gteInt_(a:BigInt, b:Int):Bool {
return BigIntArithmetic.compareInt(a, b) >= 0;
}

@:op(A >= B) @:noCompletion public static inline function gte_(a:BigInt, b:BigInt):Bool {
@:op(A >= B) @:noCompletion @:noDoc public static inline function gte_(a:BigInt, b:BigInt):Bool {
return BigIntArithmetic.compare(a, b) >= 0;
}

@:op(A >= B) @:noCompletion public static inline function gteMutable_(a:BigInt, b:MutableBigInt):Bool {
@:op(A >= B) @:noCompletion @:noDoc public static inline function gteMutable_(a:BigInt, b:MutableBigInt):Bool {
return BigIntArithmetic.compare(a, b) >= 0;
}

// String conversions
@:op(A + B) @:noCompletion public static inline function toStr_left(a:String, b:BigInt):String {
@:op(A + B) @:noCompletion @:noDoc public static inline function toStr_left(a:String, b:BigInt):String {
return a + b.toString();
}

@:op(A + B) @:noCompletion public static inline function toStr_right(a:BigInt, b:String):String {
@:op(A + B) @:noCompletion @:noDoc public static inline function toStr_right(a:BigInt, b:String):String {
return a.toString() + b;
}

// Binary addition
@:op(A + B) @:noCompletion public static inline function addInt_(a:BigInt, b:Int):BigInt {
@:op(A + B) @:noCompletion @:noDoc public static inline function addInt_(a:BigInt, b:Int):BigInt {
return new BigInt(BigInt_.addInt2(a, b));
}

@:op(A + B) @:noCompletion public static inline function add_(a:BigInt, b:BigInt):BigInt {
@:op(A + B) @:noCompletion @:noDoc public static inline function add_(a:BigInt, b:BigInt):BigInt {
return new BigInt(BigInt_.add2(a, b));
}

@:op(A + B) @:noCompletion public static inline function addMutable_(a:BigInt, b:MutableBigInt):BigInt {
@:op(A + B) @:noCompletion @:noDoc public static inline function addMutable_(a:BigInt, b:MutableBigInt):BigInt {
return new BigInt(BigInt_.add2(a, b));
}

// Binary subtraction
@:op(A - B) @:noCompletion public static inline function subInt_(a:BigInt, b:Int):BigInt {
@:op(A - B) @:noCompletion @:noDoc public static inline function subInt_(a:BigInt, b:Int):BigInt {
return new BigInt(BigInt_.subInt2(a, b));
}

@:op(A - B) @:noCompletion public static inline function sub_(a:BigInt, b:BigInt):BigInt {
@:op(A - B) @:noCompletion @:noDoc public static inline function sub_(a:BigInt, b:BigInt):BigInt {
return new BigInt(BigInt_.sub2(a, b));
}

@:op(A - B) @:noCompletion public static inline function subMutable_(a:BigInt, b:MutableBigInt):BigInt {
@:op(A - B) @:noCompletion @:noDoc public static inline function subMutable_(a:BigInt, b:MutableBigInt):BigInt {
return new BigInt(BigInt_.sub2(a, b));
}

// Binary multiplication
@:op(A * B) @:noCompletion public static inline function mulInt_(a:BigInt, b:Int):BigInt {
@:op(A * B) @:noCompletion @:noDoc public static inline function mulInt_(a:BigInt, b:Int):BigInt {
return new BigInt(BigInt_.multiplyInt2(a, b));
}

@:op(A * B) @:noCompletion public static inline function mul_(a:BigInt, b:BigInt):BigInt {
@:op(A * B) @:noCompletion @:noDoc public static inline function mul_(a:BigInt, b:BigInt):BigInt {
return new BigInt(BigInt_.multiply2(a, b));
}

@:op(A * B) @:noCompletion public static inline function mulMutable_(a:BigInt, b:MutableBigInt):BigInt {
@:op(A * B) @:noCompletion @:noDoc public static inline function mulMutable_(a:BigInt, b:MutableBigInt):BigInt {
return new BigInt(BigInt_.multiply2(a, b));
}

// Binary division
@:op(A / B) @:noCompletion public static inline function divInt_(a:BigInt, b:Int):BigInt {
@:op(A / B) @:noCompletion @:noDoc public static inline function divInt_(a:BigInt, b:Int):BigInt {
return new BigInt(BigInt_.divideInt2(a, b));
}

@:op(A / B) @:noCompletion public static inline function div_(a:BigInt, b:BigInt):BigInt {
@:op(A / B) @:noCompletion @:noDoc public static inline function div_(a:BigInt, b:BigInt):BigInt {
return new BigInt(BigInt_.divide2(a, b));
}

@:op(A / B) @:noCompletion public static inline function divMutable_(a:BigInt, b:MutableBigInt):BigInt {
@:op(A / B) @:noCompletion @:noDoc public static inline function divMutable_(a:BigInt, b:MutableBigInt):BigInt {
return new BigInt(BigInt_.divide2(a, b));
}

// Binary modulus
@:op(A % B) @:noCompletion public static inline function modInt_(a:BigInt, b:Int):Int {
@:op(A % B) @:noCompletion @:noDoc public static inline function modInt_(a:BigInt, b:Int):Int {
return BigInt_.modulusInt2(a, b);
}

@:op(A % B) @:noCompletion public static inline function mod_(a:BigInt, b:BigInt):BigInt {
@:op(A % B) @:noCompletion @:noDoc public static inline function mod_(a:BigInt, b:BigInt):BigInt {
return new BigInt(BigInt_.modulus2(a, b));
}

@:op(A % B) @:noCompletion public static inline function modMutable_(a:BigInt, b:MutableBigInt):BigInt {
@:op(A % B) @:noCompletion @:noDoc public static inline function modMutable_(a:BigInt, b:MutableBigInt):BigInt {
return new BigInt(BigInt_.modulus2(a, b));
}

// Binary OR
@:op(A | B) @:noCompletion public static inline function orInt_(a:BigInt, b:Int):BigInt {
@:op(A | B) @:noCompletion @:noDoc public static inline function orInt_(a:BigInt, b:Int):BigInt {
return or_(a, b);
}

@:op(A | B) @:noCompletion public static inline function or_(a:BigInt, b:BigInt):BigInt {
@:op(A | B) @:noCompletion @:noDoc public static inline function or_(a:BigInt, b:BigInt):BigInt {
return new BigInt(BigIntArithmetic.bitwiseOr(a, b));
}

@:op(A ^ B) @:noCompletion public static inline function xorInt_(a:BigInt, b:Int):BigInt {
@:op(A ^ B) @:noCompletion @:noDoc public static inline function xorInt_(a:BigInt, b:Int):BigInt {
return xor_(a, b);
}

@:op(A ^ B) @:noCompletion public static inline function xor_(a:BigInt, b:BigInt):BigInt {
@:op(A ^ B) @:noCompletion @:noDoc public static inline function xor_(a:BigInt, b:BigInt):BigInt {
return new BigInt(BigIntArithmetic.bitwiseXor(a, b));
}

@:op(~A) @:noCompletion public static inline function not_(a:BigInt):BigInt {
@:op(~A) @:noCompletion @:noDoc public static inline function not_(a:BigInt):BigInt {
return new BigInt(BigIntArithmetic.bitwiseNot(a));
}

// Binary AND
@:op(A & B) @:noCompletion public static inline function andInt_(a:BigInt, b:Int):Int {
@:op(A & B) @:noCompletion @:noDoc public static inline function andInt_(a:BigInt, b:Int):Int {
return BigIntArithmetic.bitwiseAndInt(a, b);
}

@:op(A & B) @:noCompletion public static inline function and_(a:BigInt, b:BigInt):BigInt {
@:op(A & B) @:noCompletion @:noDoc public static inline function and_(a:BigInt, b:BigInt):BigInt {
return new BigInt(BigIntArithmetic.bitwiseAnd(a, b));
}

// Binary shift left
@:op(A << B) @:noCompletion public static inline function asl_(a:BigInt, b:Int):BigInt {
@:op(A << B) @:noCompletion @:noDoc public static inline function asl_(a:BigInt, b:Int):BigInt {
return new BigInt(BigInt_.arithmeticShiftLeft2(a, b));
}

// Binary shift right
@:op(A >> B) @:noCompletion public static inline function asr_(a:BigInt, b:Int):BigInt {
@:op(A >> B) @:noCompletion @:noDoc public static inline function asr_(a:BigInt, b:Int):BigInt {
return new BigInt(BigInt_.arithmeticShiftRight2(a, b));
}

//-----------------------------------------------------------------------
// Automatic conversions
//-----------------------------------------------------------------------

@:from @:noCompletion public static inline function fromInt_(a:Int):BigInt {
@:from @:noCompletion @:noDoc public static inline function fromInt_(a:Int):BigInt {
return new BigInt(BigInt_.fromInt(a));
}

@:from @:noCompletion public static inline function fromString_(a:String):BigInt {
@:from @:noCompletion @:noDoc public static inline function fromString_(a:String):BigInt {
return new BigInt(BigInt_.fromString(a));
}

@:to @:noCompletion public inline function toBigInt_():BigInt_ {
@:to @:noCompletion @:noDoc public inline function toBigInt_():BigInt_ {
return this;
}

@:to @:noCompletion public inline function toMutableBigInt():MutableBigInt {
@:to @:noCompletion @:noDoc public inline function toMutableBigInt():MutableBigInt {
return new MutableBigInt(MutableBigInt_.fromBigInt(this));
}

//-----------------------------------------------------------------------
// Private implementation
//-----------------------------------------------------------------------

@:noCompletion private inline function new(a:BigInt_) {
@:noCompletion @:noDoc private inline function new(a:BigInt_) {
this = a;
}

4 changes: 2 additions & 2 deletions std/haxe/math/bigint/BigIntExceptions.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C)2005-2022 Haxe Foundation
* Copyright (C)2005-2023 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -23,7 +23,7 @@
package haxe.math.bigint;

/* Original code courtesy Chuck Batson (github.com/cbatson) */
enum abstract BigIntExceptions(String) {
enum abstract BigIntExceptions(String) to String {
Copy link
Contributor

@sebthom sebthom Mar 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just looked at the failing test. I think it is actually the other way around. enum abstract BigIntExceptions(String) from String if you want to use it like

} catch (e:String) {
   eq(BigIntExceptions.INVALID_ARGUMENT, e);
}

Maybe even better you do a catch-all:

} catch (e) {
   eq(BigIntExceptions.INVALID_ARGUMENT, e);
}

Then I believe you should don't need the from/to declarations at all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think adding from String there would be nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there are at least three options here:

  1. Return the first draft ( using class and string)
  2. Using enum abstract ( with from String to String ) similiar to Tink's approach ( https://github.com/haxetink/tink_core/blob/master/src/tink/core/Error.hx#L23)
  3. Extend haxe.Exception

The question here is how does the end user want to proceed with the error ?
Does it want to match it with if/else/switch case or trace the stack or something else ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the exceptions are strings and some other code throws a string exception with exactly the same value e.g. Invalid argument then the end user is not be able to distinguish that properly. So maybe typed exceptions might be better. When you search through the haxe std library however, there is no consistency and no clear direction visible what is the preferred approach (strings vs exception objects). No one really seems to care.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the other solution that I think was to create a BigInteException class (extends haxe.Exception) and create а new BigIntError.hx class ( which will use the current enum abstract implementation)
Example:

  1. BigIntError.hx
    enum abstract BigIntError(String) to String{
     var INVALID_ARGUMENT = "Invalid argument";
      .....
    }
  1. BigIntException.hx
class BigIntException extends haxe.Exception {
	public function new(error:BigIntError, ?previous:haxe.Exception) {
		super( error, previous);
	}
}

and call it with throw new BigIntException(BigIntError.INVALID_ARGUMENT);
If this is a better solution, I could implement it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good idea. Exceptions even if thrown as strings anyway result in the instantiation of an exception object, in this case haxe.ValueException. So there is also no performance drawback if you use a dedicated exception class.

var INVALID_ARGUMENT = "Invalid argument";
var BUFFER_TOO_SMALL = "Buffer too small";
var DIVISION_BY_ZERO = "Division by zero";
4 changes: 3 additions & 1 deletion std/haxe/math/bigint/BigInt_.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C)2005-2022 Haxe Foundation
* Copyright (C)2005-2023 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -26,6 +26,8 @@ import haxe.ds.Vector;
import haxe.io.Bytes;

/* Original code courtesy Chuck Batson (github.com/cbatson) */
@:noCompletion
@:noDoc
@:allow(unit)
@:allow(haxe.math.bigint)
class BigInt_ {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@:allow has no effect on public classes.

Classes not meant for access outside the package should preferably be added to other modules as private classes (i.e. in this case to BigInt.hx) or at least have the @:noCompletion and @:noDoc annotations added to prevent the types from being suggested by the completion server and from showing up in the API docs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@:allow has no effect on public classes

It does? It's about giving access to its private fields.
But it won't allow access to a private class from outside its module if that's what you're suggeting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant it has no effect on visibility of the class itself. All these classes ending with underscore are - as far as I understand - internal implementation classes, but they are accessible from outside the package and the completion server suggests them during auto completion requests. This should not be the case. Since Haxe has no package visible modules, these classes should be implemented as private classes inside the public module, i.e. the module holding the public abstract.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well,for me a separate BigInt_ class leads to more readability, so I've added @:noCompletion and @:noDoc for now. If this is against the Haxe standart, I can put a BigInt_.hx class inside BigInt.hx ( and MutableBigInt_)

Loading