|
Wikipedia sez:
i^4n = i
i^(4n+1) = 1
i^(4n+2) = -i
i^(4n+3) = -1 |
|
|
OOPS SORREH
i^4n = 1
i^(4n+1) = i
i^(4n+2) = -1
i^(4n+3) = -i |
|
CardCaddyJoin Date: 2010-01-02 Post Count: 1025 |
Basically, thats right. |
|
|
ShokwavJoin Date: 2008-08-16 Post Count: 9263 |
It's not complicated.
local i={}
setmetatable(i, {__add=function(a, b)
if not (a==i or b==i) then return print(tostring(nil)) end
if type(a)==i then return b.."i" else return a.."i" end
end,
})
local a = 12 + i
print(a)
12i |
|
|
...
You said it was complicated, therefore it is! You do not deny your own words, my brother!
http://www.roblox.com/The-Roblox-Lua-math-i-library-v1-6-item?id=43522190
UPDATE: Added cube roots. |
|
|
@Shok: You can't add an imaginary number and a real number. |
|
ShokwavJoin Date: 2008-08-16 Post Count: 9263 |
By complicated, I meant inefficient. |
|
ShokwavJoin Date: 2008-08-16 Post Count: 9263 |
@Revolution: I never tried to. Look at my code. |
|
|
YOU CANNOT ADD AN IMAGINARY NUMBAH AND TEH REAL NUMBAH!!!!1!1!1!11!11!!!!1111!!ONE!1! |
|
|
T_T
Guys, stop if you're just going to make a replacement for my script... D: |
|
ShokwavJoin Date: 2008-08-16 Post Count: 9263 |
I.never.tried.to. |
|
|
@Shokky
Cover of a mistake. |
|
|
"local a = 12 + i"
The answer is "12 + i". It's not "12i". |
|
|
You guys noticed my updates?
http://www.roblox.com/The-Roblox-Lua-math-i-library-v1-6-item?id=43522190
If you're too lazy to take it, here's the code:
--[[ math.i created by vanillaluv 2011
put no spaces
ex:
mathi(-9)
]]
function mathi(equation) -- call the function
a = equation*equation -- convert negative to positive
b = math.sqrt(a) -- get the square root of the positive new number
final = "The square root of "..equation.." is "..tostring(math.sqrt(b)).."i. " -- get the square root of the square root of the new positive number
return final -- give us what you did
end -- end the function
-- put the rest of your script here, use this template for your math:
print(mathi(-9))
-- [[ UPDATE: Allows cuberoots ]]
function mathic(equation)
a = equation*equation
b = math.sqrt(a)
c = b/3
d = math.sqrt(c)
print("The cube root of "..equation.. " is "..d.."i. ")
end
print(mathic(-27))
-- NEXT UPDATE: dealing with floats
print("NEXT UPDATE: dealing with floats") |
|
ShokwavJoin Date: 2008-08-16 Post Count: 9263 |
I did that because there is no __pow metamethod. |
|
|
FAILLL
SO TOTALLY FAILED THAT SO MUCH IN SO MANY WAYS |
|
ShokwavJoin Date: 2008-08-16 Post Count: 9263 |
"function mathic(equation)
a = equation*equation
b = math.sqrt(a)
c = b/3
d = math.sqrt(c)
print("The cube root of "..equation.. " is "..d.."i. ")
end "
local mathic=function(a)
b=(((a*a)^0.5)/3)^0.5
return a, print(string.format("Cubic root of %s: %s.", a, b))
end
Seriously, aim for maximum efficiency. |
|
ShokwavJoin Date: 2008-08-16 Post Count: 9263 |
Lol, how did I fail? |
|
|
@Shok
Okay, I'll do that... :P |
|
|
"function mathic(equation)
a = equation*equation
b = math.sqrt(a)
c = b/3
d = math.sqrt(c)
print("The cube root of "..equation.. " is "..d.."i. ")
end "
huh? Two things: First, cube roots of negative numbers are always real. Second, a cube root isn't just the square root of a number divided by three. It's the number that, when multiplied by itself three times, returns your original number. |
|
ShokwavJoin Date: 2008-08-16 Post Count: 9263 |
...Except that my b would be better off local. |
|
|
No, you didn't fail, I failed. Look at my math.
mathic(-64)
> 4. ( one heck of a float here )
-.-
So how would I do that? |
|
|
|
Lua can do cube roots of negative numbers by itself. print((-64)^(1/3)) |
|