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 "mod" function to FlxMath #3341

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open

add "mod" function to FlxMath #3341

wants to merge 3 commits into from

Conversation

cyn0x8
Copy link

@cyn0x8 cyn0x8 commented Jan 23, 2025

this pr adds a more "mathematically accurate" alternative to the built-in modulo operator to FlxMath as a helper function


haxe a % b behavior (truncated division):

Divmod truncated.svg

By Mathnerd314159 - Own work based on: Divmod.svg by Salix alba, CC BY-SA 3.0, Link


a mod b behavior (euclidean division):

Divmod Euclidean.svg

By Mathnerd314159 - Own work based on: Divmod.svg by Salix alba, CC BY-SA 3.0, Link

@@ -573,4 +573,13 @@ class FlxMath
{
return (n > 0) ? n : -n;
}

/**
* Returns `a mod b`.
Copy link
Member

@Geokureli Geokureli Jan 23, 2025

Choose a reason for hiding this comment

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

The doc should explain what "mod" is, the difference between this and haxe's % operator and give at least one key example of that difference

Copy link
Member

Choose a reason for hiding this comment

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

also we should add that example and others to the unit test

@cyn0x8 cyn0x8 requested a review from Geokureli January 23, 2025 20:18
@@ -575,7 +575,15 @@ class FlxMath
}

/**
* Returns `a mod b`.
* Performs a modulo operation on two numbers.
Copy link
Member

Choose a reason for hiding this comment

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

What about?

Suggested change
* Performs a modulo operation on two numbers.
* Performs a modulo operation to calculate the remainder of `a` divided by `b`

I want it to actually say what modulo/mod is

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.

2 participants