The problem
Non-even roots on negative numbers break mathematics in Lua/Luau.
The equation (x) ^ (1/y)
, where x is any negative number, and y is any non-even number should always be equal to -(math.abs(x) ^ (1/y))
. Instead, (x) ^ (1/y)
returns -nan(ind)
.
From testing, this same bug happens in a range of other programming languages as well, including non-roblox lua and C.
Reproduction Steps
Simply in a script/console, type print((-1) ^ (1/3))
Expected Behavior
The result should always equal to -(math.abs(x) ^ (1/y))
Plotting the graph of x^(1/3)
as proof that it should equal -1.
Actual Behavior
The result is -nan(ind)
for any non-even root of a negative number.
Issue Area: Engine
Issue Type: Other
Impact: Moderate
Frequency: Constantly
Date First Experienced: 2021-12-06 00:12:00 (+00:00)
Date Last Experienced: 2021-12-06 00:12:00 (+00:00)
Any queries or quarrel please direct them to @jaschutte