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

I have no idea how to write code for multiplying an int128 #11749

Closed
SomeGuyWhoLovesCoding opened this issue Aug 23, 2024 · 1 comment
Closed

Comments

@SomeGuyWhoLovesCoding
Copy link

/**
	Returns the product of `a` and `b`.
	The code is different from Int64's `mul(a, b)` because it causes problems for values that represent higher than 64 bits.
**/
@:op(A * B)
public static #if !lua inline #end function mul(a:Int128, b:Int128):Int128 {
	return make(b.high * a.high, (a.low * b.low));
}

This here is the current multiplication function.
When it goes up to 18 quintillion (which is the maximum unsigned 64 bit number), it's supposed to increment the high value. But, it appears that I can't really do that.
The trace if you want to see what's going on:

MULTIPLY TEST
10
Low: 100
100
Low: 1000
1000
Low: 10000
10000
Low: 100000
100000
Low: 1000000
1000000
Low: 10000000
10000000
Low: 100000000
100000000
Low: 1000000000
1000000000
Low: 10000000000
10000000000
Low: 100000000000
100000000000
Low: 1000000000000
1000000000000
Low: 10000000000000
10000000000000
Low: 100000000000000
100000000000000
Low: 1000000000000000
1000000000000000
Low: 10000000000000000
10000000000000000
Low: 100000000000000000
100000000000000000
Low: 1000000000000000000
1000000000000000000
(This is where the number bugs out)
Low: -8446744073709551616
10000000000000000000
Low: 7766279631452241920
7766279631452241920

I'm trying to write an Int128 for haxe btw.
Here are the files:
Int128.txt
Int128Helper.txt
Int64.txt
Int64Helper.txt

@Simn
Copy link
Member

Simn commented Aug 24, 2024

See #11750

@Simn Simn closed this as completed Aug 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants