Doing math.huge on a value is making it negative math.huge

Hello!
I was just wondering why whenever I do math.huge on a value the value turns negative

1 Like

Can you provide some code to go with this?

Since math.huge is infinite, it’s bound to be negative due to it exceeding the maximum limit of a value. This is actually something common in other game engines which I’ve seen.
When you set a value, you can try setting it to the absolute value of what it is after the change.

and how do u set an abs value?

number math.abs ( number x )
Returns the absolute value of x

1 Like
SomeNumberValue.Value = math.huge
SomeNumberValue.Value = math.abs(SomeNumberValue.Value)
1 Like

Ok! thank you I never knew about absolute value Thank you for the quick comments :grinning:

2 Likes

Quoting the first statement I made,

Since math.huge doesn’t have a minute, but NumberValues and IntValues and basically anything else does, it will be negative. I’ve tested this.

Edit: I’ve tested this on a frame’s LayoutOrder. IntValues set to math.huge will just be reset to its previous value. and NumberValue will say “INF”.
image
This is what I have been explaining.

weird, when I test it in Roblox Studio the value comes out positive but when I test in real game it’s still negative

script

Args = {"Player"};
		Function = function(speaker, args)
			local plr = args[1]
			local Max = plr.MaxHunger
			
			if plr then
				Max.Value = math.huge
				Max.Value = math.abs(Max.Value)
			
				plr.HungerValue.Value = Max.Value
			end
		end;
		UnFunction = function(speaker, args)
			local plr = args[1]
			local Max = plr.MaxHunger
			
			if plr then
				Max.Value = 100
				plr.HungerValue.Value = Max.Value
			end
		end;

May I ask why you are setting this “Max” value to math.huge? It seems useless, aside from doing something to break your game.

im working on my games admin commands

That doesn’t really answer my question. I need to know why you are setting “Max” to math.huge in the first place.

Max is the max hunger you can have in the game and hunger value is the value your hunger is.

You don’t need to be setting it to math.huge, though, instead just set it to a high number like a million, or just have it as 100. I don’t really understand what this function is for.

As far as I understand it, math.huge doesn’t represent a number, more of a value that is so large it cannot fit inside a double. It is useful because any number that is too large will evaluate to be equal to math.huge, check out this post if you want to know more.

1 Like

so, I should just set the value as the max which is 9223372036854775807?

That is the maximum value of a 64 bit signed integer, yes. I am not sure how lua will react if you try to mess normal numbers with math.huge, so if you want to do operations and comparisons than yeah it’d probably be best to stay within the limits.

EDIT: A double has a larger capacity than an integer, by the way. Also, what is the point of such a large maximum? If you want it to just be able to fit into a number value, simple check if it equals math.huge, because if it does that means it won’t fit (don’t quote me on this).

1 Like