InfiniteMath | Go above 10^308/1e+308!

There’s a few ways you can construct a number

IM.new(1000)
IM.new(1e+3)
IM.new("1, 3")

Will all give you 1000. You need to use the bottom string method to generate anything over 1e+308, the module just gets INF when it gets that so I can’t use it, hence the string method.

2 Likes
  1. Because of how numbers are stored as strings, you can’t use normal math methods or functions with them. A number is stored as a coefficient and an exponent, so I have to do the math with 2 separate numbers instead of 1. Metamethods are used so you can still use +, -, etc. without needing to call functions, and things like math.sqrt, math.clamp, math.floor, etc. exist as functions.

  2. I started the module, but 3 other people have contributed to it as well, so there might be some differences in coding style being used.

2 Likes

A better solution would be to use physics sectors. In simple terms, divide the map into sectors. If 2 sectors are neighbors, group them, then perform physics separately on each group. Don’t get me wrong, this method is pretty impressive and fast, but it’s not even close to floating point math in terms of performance or precision for that matter. You won’t notice an impact if you perform math on 1 or even 50 of these, but physics often requires hundreds of calculations per object every frame.

I actually had at some point thought of something like this, dividing the world into different chunks and also having “scenes” in one server so you can have 2 workspaces in one server so that way you can like do the physics work for 1 area in 1 workspace and the rest on the 2nd workspace.

1 Like

Just updated the module to 1.1.2 to add log and log10.

I believe most of the important math functions have now been added, if there are other math functions you need I will try to implement them.

1 Like

how do you compare number with this? example
currentVal = InfM.new(Val):ScientificNotation(false)
if currentVal >= reqVal then – err got cant compare number with table
if i make it into tonumber() i scared it will be INF

2 Likes

ScientificNotation is for displaying numbers, it gives you a string, you only use that when you want to have a text or something shown to the player.

This is because of a limitation in metamethods. Basically, you can’t compare InfM numbers with normal numbers. The fix is to just create a new InfM number to compare it to.

if currentVal >= InfM.new(reqVal) then

tonumber() won’t have an affect on InfM numbers, as there is no metamethod with it.

If you want to convert numbers from InfM back into normal numbers, there is a Reverse function of InfM numbers which returns a normal number, but if the number is above 1e+308 it will return INF, so be careful with that.

1 Like

that mean bit useless i using this module for limited feature

1 Like

how can give a example of the usage

1 Like

Its not useless because of this, you just only use Reverse when you know for sure a number will be below 1e+308.

You can still do basic math, math functions, and comparison fine.

Instead of doing

local Val = InfiniteMath.new(50)

if Val == 50 then

You just have to do

local Val = InfiniteMath.new(50)

if Val == InfiniteMath.new(50) then

Its sadly unavoidable because metamethods for ==, >, >=, etc. Will only accept numbers unlike +, -, *, etc. which can accept tables as well.

1 Like

can you fix the module performance, it lagged after like 100x bulk every 0.01s per player, its not much laggy if only alone in the server but it lagged if more than 1

2 Likes

I can look into performance, thanks for letting me know.

I’ve posted an issue on the GitHub. I took a look at it and tried a few different things, but it was either negligible or worse for performance.

For now, I recommend not doing so many calculations per second. If your game is what I think it is, instead of doing 100x calculations every .01 second, why not do 1 calculation every .01 and multiply it by 100.

You would get more or less the same effect, I doubt anyone would notice or care that its not doing 100 calculations every .01.

its heating for using to many of Inf.new(0) or Inf.new(1) or inf.new(number) due ur not module not work for non number, If you could make it able to comparing with number (>=, <= , >, <, ==, ~=, not), i make like 20-35% less usage of it but it only increase likely 1-3 fps, but its still worst because each player make server fps to 10-12 fps from 60, 3 players can make 2-4 fps

Internally it wouldn’t matter if you could use ==, <, >, etc. with Inf numbers and normal numbers, because every equation that uses a normal number and Inf number will use Inf.new() on the normal number, that’s how I can support math between Inf numbers and normal numbers.

The module uses strings for lots of stuff, my idea for optimization would probably start there, but its already been so optimized I’m not sure what else can be done.

no i mean if you could make InfM that could use ==, <, >, more to normal number (non InfM number), like Inf.new(0) >= 0 – it will err because cant compare table with number, i know it cant because like u said before using metamethod

That’s a problem Unity also has, in fact in Subnautica (which uses Unity) the farthest from the center you will go, the more your character will tremble, if you get past the invisible teleport wall you will reach a point where you will not be able to recognise yourself anymore :rofl::rofl::rofl:

1 Like

Yes that’s what I mean. What the metamethod for +, -, etc. does is it’ll take the table and the actual number, it’ll convert the normal numbers into InfiniteMath numbers by using InfiniteMath.new().

It would have the exact same or similar performance even if metamethods would allow it, all that would change is convenience.

but using too many InfM.new() taken performance

Yeah, but math metamethods will convert normal numbers using InfiniteMath.new(), and so would comparison metamethods if they worked. It’s still the same performance hit whether it uses new() inside or outside the module.