Reciprocal of a Number

I’ll keep this short.

This term is used in more complicated math, called a “reciprocal”. It gets the complete opposite of a number, usually used for inverting graphs’ gradients or other scalar calculations.

This is an example on what these numbers’ reciprocals are:

0 --> 0
1 --> -1
2 --> -0.5
3 --> -1/3
-5 --> 0.2
2.4 --> -5/12

…or you can just google what a reciprocal is.

My question is, how can I do this in Roblox? I couldn’t find the answer anywhere. If you have any suggestions or solutions, then please comment it down below. Thank you.

1 Like

Yeah, this is possible but it’s outside of my skill level. Though it is possible, I just don’t know how to get an integer.

local x = 0.2 --how do we know this is 1/5?
--we can see how many times it goes through one.
local int, decimal = math.modf(x)
local timesItGoesIntoOne = 1/decimal
local reciprocalOfTheFraction = -timesItGoesIntoOne --this is all we need for 0.2
print(reciprocalOfTheFraction) --> -5
--local reciprocalOfTheDecimal = -(timesItGoesIntoOne+(int*timesItGoesIntoOne)) --this is probably wrong, and I'm not sure how to do this.
1 Like

it’s just -1/number
very simple ik

-1/1 = -1
-1/2 = -0.5
-1/3 = -1/3 -- 😮
-1/4 = -0.25
-1/-5 = 1/5 = 0.2 -- the two negatives cancel out lol
.
.
.

unfortunately, print always gives decimal notation or scientific notation (1.23e4)

Man, this makes my work look so overly complicated. That’s what happens when you think at midnight.

But shouldn’t -1/3 equal 3/1? I might be confused, but that seems weird to me.

But the negative number is kept. 2 should be set to -1/2, a negative.

1 Like

yea

function reciprocal(x)
    return -1/x
end
1 Like

If I put 0 then it would return a negative-infinite number.

yea ik that
and in fact when i google “reciprocal of 0”, i get undefined

and there’s a weird ted ed vid about how “1/0 = plus/minus infinity” can break maths

Why are you making it negative?

The reciprocal of x is just 1/x.

1 is 1/1 so it equals 1
2 = .5
3 = .33333 (or 1/3)
-5 = -.2
2.4 = .4166667 (or 5/12)

6 Likes

I thought you would have to make it negative. I guess I don’t pay attention in math class. :expressionless:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.