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

math: fix division with negative numbers (fix #19585) #19588

Closed
wants to merge 1 commit into from

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Oct 17, 2023

This PR fix division with negative numbers (fix #19585).

  • Fix division with negative numbers.
  • Add test.
import math.big

fn main() {
	// Correct: 123
	r1 := big.integer_from_int(1234) / big.integer_from_int(10)
	println(r1)
	assert '${r1}' == '123'

	// Incorrect: -124
	r2 := big.integer_from_int(-1234) / big.integer_from_int(10)
	println(r2)
	assert '${r2}' == '-123'

	// Correct: -123
	r3 := big.integer_from_int(1234) / big.integer_from_int(-10)
	println(r3)
	assert '${r3}' == '-123'

	// Incorrect: 124
	r4 := big.integer_from_int(-1234) / big.integer_from_int(-10)
	println(r4)
	assert '${r4}' == '123'
}

PS D:\Test\v\tt1> v run .
123
-123
-123
123

@yuyi98 yuyi98 closed this Oct 17, 2023
@yuyi98 yuyi98 deleted the fix_math_big_div branch October 17, 2023 07:37
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

Successfully merging this pull request may close these issues.

math.big: Incorrect division with negative numbers
1 participant