Issues with doing math, numbers are too big and return inf

I am doing some math calculations with os.time() to calculate what I need to divide another value by just returns inf since it is bigger then the 2^53 limit or whatever, how can I fix this? (For reference this is what I am doing)

local time = os.time()
local g = math.pow(time, #key - i) -- 0-32
character * g -- num * g

then trying to undo it

local g = math.pow(time, #key - i);
g = character / g;
print(g) -- prints inf, should be the original "character" value...

What is the value of character where it prints inf?

Character is just a number in a string, I get each character in a string, if it is a number multiply it isn’t character that is the issue.

If you put in a dummy value for character like 2, does it still print inf?

Yes it does still print inf it is the os.time() I believe.

That’s odd, I tried testing this myself with this script:

local time = os.time()
local g = math.pow(time, 32) 
local character = g * 2
print(character)
print(character/g)

And unless I’m misunderstanding your problem, everything should work fine, since it never prints inf. It’s not something with os.time().

The only way I can replicate your error is by having the second argument of math.pow() be greater than 1.365. You should print #key - i to ensure that it really is -32. Unless you mean that it will count from 0 to 32 in which case, that’s the problem.

i is a value that is counting from 32, to 0

How large is #key
wow… why is the term 31-1chars not allowed? Sometimes I need a clarification in under that amount of chars and it’s a brief explanation of the extra characters. Ohh well, my mini rant was enough to get me past the minimum character limit

Actually why do you need to use math.pow on time? I’m pretty sure that’s your issue, but without context I can’t really see why you need it. Can’t you just not encrypt the data? Then you wouldn’t need to unencrypt it.

Here is encrypting:

for i = #key, 1, -1 do
				local character = string.sub(key, #key - i + 1, #key - i + 1); -- if #key is 10, and i = 7, then it is 4
                if #key - i + 1 > #key then
                    character = string.sub(key, #key, #key);
                end
				if tonumber(character) then
                    hashedKey[i] = character;
                    local g = math.pow(LockService.Salt[player.UserId], #key - i); -- if #key is 10, and i = 7, then it is 3
                    --local num = string.byte(character) * g;
					hashedKey[i] = character * g;

				else
					hashedKey[i] = character
                end 
            end

the “salt” is os.time(), basically the key to encrypting and decrypting
Decrypting:

for i = #key, 1, -1 do
            local character = key[i];
            print(character)
            if tonumber(character) then
                local g = math.pow(salt, #key - i); -- 10, i = 7, g = 3
                g = character / g;
                print(g)
                decrypt = decrypt .. tostring(g);
            elseif character ~= nil then
                decrypt = decrypt .. character;
                print(character, "string")
            else
                print("Neither?", character);
            end
        end

This is not unusual. os.time() returns a fairly large number, around ten digits, whose negative power is a number so small that it exceeds the lower limit of an IEEE 64-bit floating-point number. It is so small that it is simply interpreted as zero. So any number divided by zero is Infinity.

You might consider using a fraction of os.time() or scaling it in some way to avoid that overflow.

the highest number you can get is 2147483647

( I think )

Roblox’s limits are higher than that; Some numbers I have seen are upwards of QD

edit: NumberValue
They use 64 bit for number saving, or about 9QD

1 Like

Yeah tried that, even with 2 it prints inf…