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

Script API: add a equivalent of "truncate" to FloatToInt modes #1983

Open
ivan-mogilko opened this issue Apr 21, 2023 · 1 comment · May be fixed by #2684
Open

Script API: add a equivalent of "truncate" to FloatToInt modes #1983

ivan-mogilko opened this issue Apr 21, 2023 · 1 comment · May be fixed by #2684
Labels
ags 4 related to the ags4 development context: script api type: enhancement a suggestion or necessity to have something improved

Comments

@ivan-mogilko
Copy link
Contributor

ivan-mogilko commented Apr 21, 2023

FloatToInt currently supports 3 modes:

  • eRoundDown - this is eq to C floor (or C++ std::floor): it finds the closest integer literally <= than the given float.
  • eRoundUp - this is eq to C ceil: it finds the closest integer >= given float.
  • eRoundNearest - this is eq to C round: it rounds to the closest integer.

What is missing here is "truncate": the one that finds a closest integer which is less by magnitude. We may call this eRoundTruncate (unless someone suggests a better name).

The difference between floor and trunc is that for the floor (eRoundDown):
+1.5 = +1
-1.5 = -2
and for trunc (eRoundTruncate):
+1.5 = +1
-1.5 = -1

NOTE: also, the FloatToInt implementation in the engine should be rewritten to use libc or std C++ functions. done

EDIT: In fact, we might also add a mode opposite to "truncate", which finds nearest integer greater by magnitude. The C/C++ do not have the ready function for this, but it may be implemented like

return x < 0 ? floor(x) : ceil(x);
@ivan-mogilko ivan-mogilko added type: enhancement a suggestion or necessity to have something improved ags 4 related to the ags4 development context: script api labels Apr 21, 2023
@AlanDrake
Copy link
Contributor

We could name them eRoundToZero and eRoundAwayFromZero,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ags 4 related to the ags4 development context: script api type: enhancement a suggestion or necessity to have something improved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants