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.
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.
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.
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.
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
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.
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
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
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.
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.