Skip to content

Number static data properties#1492

Merged
Perryvw merged 17 commits intoTypeScriptToLua:masterfrom
Z3rio:number-literals
Sep 27, 2023
Merged

Number static data properties#1492
Perryvw merged 17 commits intoTypeScriptToLua:masterfrom
Z3rio:number-literals

Conversation

@Z3rio
Copy link
Copy Markdown
Contributor

@Z3rio Z3rio commented Sep 25, 2023

This is not done, please do not merge yet. Tests will be added once all data properties have been added.

This PR aims to provide all the data properties from JS's Number library.

Closes: #1108

Progress:

  • ✅NEGATIVE_INFINITY
  • ✅POSITIVE_INFINITY
  • ✅NaN
  • ✅MIN_VALUE
  • ✅MIN_SAFE_INTEGER
  • ✅MAX_VALUE
  • ✅MAX_SAFE_INTEGER
  • ✅EPSILON

@Zamiell
Copy link
Copy Markdown
Contributor

Zamiell commented Sep 25, 2023

amazing pr thank you!

@Z3rio
Copy link
Copy Markdown
Contributor Author

Z3rio commented Sep 25, 2023

All of them have now been set up, I'll have to go through them and check that they are all correct, then I'll go ahead and write tests for them all.

@Z3rio
Copy link
Copy Markdown
Contributor Author

Z3rio commented Sep 25, 2023

@Perryvw Do you think stuff like this should have testcases? And if so, what do you want us to test?

I was looking at transformMathProperty, aka the closest thing I could find to this. https://github.com/TypeScriptToLua/TypeScriptToLua/blob/master/src/transformation/builtins/math.ts#L9
Which does not seem to have any test cases either

Copy link
Copy Markdown
Member

@Perryvw Perryvw left a comment

Choose a reason for hiding this comment

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

These are indeed tricky to test since we can't compare them to the JS values. However, I think we can test their relative sizes within Lua? This somewhat sneakily also tests they are translated into correct code without compiler or runtime exceptions :)

I'm thinking something like:

test.each([
    "Number.NEGATIVE_INFINITY < Number.MIN_VALUE",
    "Number.MIN_VALUE < Number.MIN_SAFE_INTEGER",
    "Number.MIN_SAFE_INTEGER < 0",
    "0 < Number.EPSILON",
    "Number.EPSILON < Number.MAX_SAFE_INTEGER",
    "Number.MAX_SAFE_INTEGER < Number.MAX_VALUE",
    "Number.MAX_VALUE < Number.POSITIVE_INFINITY"
])("Numer constants have correct relative sizes (%p)", comparison => {
    util.testExpression(comparison).expectToEqual(true);
});

@Z3rio
Copy link
Copy Markdown
Contributor Author

Z3rio commented Sep 26, 2023

Those tests look good yeah, but the Number.MAX_VALUE < Number.POSITIVE_INFINITY seem to fail, since lua interprets both as Infinity

So... for example in MAX_VALUE, do you think we should base that off of Lua's max value, or Javascript's max value? Because right now it is based off of Javascript's documentation.

@Perryvw Perryvw merged commit c85001e into TypeScriptToLua:master Sep 27, 2023
@lolleko lolleko mentioned this pull request Mar 28, 2026
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.

Transpile Number.POSITIVE_INFINITY to math.huge

3 participants