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 lib update #1477

Open
wants to merge 3 commits into
base: master
from
Open

Math lib update #1477

wants to merge 3 commits into from

Conversation

@Kefta
Copy link
Contributor

Kefta commented Apr 19, 2018

  • Added math.BitCount( number num ) - returns the least amount of bits needed to represent an integer in binary. This function can be used with networking indexes for shared tables in the most network-efficient manner
  • Added math.IntToString( number num, number [2, 36] base, boolean caps = false ) - this is the opposite of tonumber and will convert a decimal number to a base [2, 36] string. You can now achieve the same effect as math.IntToBin (be it a little less efficient) with this. The caps argument determines if the output string's characters should be capitalised (base 11+)
  • Added math.DistanceSqr( number x1, number x2, number y1, number y2 ) - returns the distance squared between two points (more efficient than math.Distance)
  • math.IntToBin's string return no longer has leading zeros
  • Fixed infinite loop with bad arguments to math.calcBSplineN/BSplinePoint
  • Localised global/library functions
  • Overall optimisations
- Added math.BitCount( number num ) - returns the least amount of bits needed to represent an integer in binary. This function can be used with networking indexes for shared tables in the most network-efficient manner
- Added math.IntToString( number num, number [2, 36] base, boolean caps --[[= false]] ) - this is the opposite of tonumber and will convert a decimal number to a base [2, 36] string. You can now achieve the same effect as math.IntToBin (be it a little less efficient) with this function. The caps arguments determines if the output string's characters should be capitalised (base 11+)
- Added math.DistanceSqr - returns the distance squared between two points (faster than math.Distance)
- math.IntToBin's return no longer has leading zeros
- Fixed potential infinite loop with bad arguments to math.calcBSplineN/BSplinePoint
- Localised global/library functions
- Minor optimisations to some functions
@thegrb93

This comment has been minimized.

Copy link
Contributor

thegrb93 commented Apr 19, 2018

A few useful ones I use commonly; Not important, but might be useful to some.
math.step - http://www.wolframalpha.com/input/?i=H(x)
math.sign - http://www.wolframalpha.com/input/?i=2*H(x)-1 (except x=0 should be 0)

@Kefta

This comment has been minimized.

Copy link
Contributor Author

Kefta commented Apr 20, 2018

Those would be more efficiently implemented inline, and they're just one-liners that wouldn't save much time in typing either - math.Sign was denied for this purpose: #1229

@thegrb93

This comment has been minimized.

Copy link
Contributor

thegrb93 commented Apr 20, 2018

There's quite a few things in there that are more efficient inline. The point is that its easier to type math.sign rather than doing the inline everytime.

I guess they are too trivial to be added, but still; they make writing some things faster.

@Grocel

This comment has been minimized.

Copy link

Grocel commented May 24, 2018

Wouldn't math.Clamp better implemented inline as well? So why is it in again?

@Kefta

This comment has been minimized.

Copy link
Contributor Author

Kefta commented May 24, 2018

It already is inlined from LuaJIT (math.max and min at least).

@Kefta

This comment has been minimized.

Copy link
Contributor Author

Kefta commented May 29, 2018

IntToString now checks its base's bounds like tonumber. Lua 5.2 does not error for non-integer numeral representations like 5.3, so I left the unsigned int cast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.