the Immortal
I know, I know...
- Reaction score
- 51
So ... I need to do some math with really huge (for the WE ... ) numbers which, it seems, aren't supported. Like, for example:
var1 is [1;18750]
var2,var3,var4,var5 are [1;4200]
So in the end I may get something like
... which, as I said, WE can't handle
Well, so I made 2 functions -- 'Add' and 'Multiply' that take strings, work with numbers from 0-19 and work perfectly with 'normal' numbers (tho they should work with huge numbers like mine):
Well, multiplying numbers like 5324 and 9812 works perfectly using these functions ... but! When I do something like:
call BJDebugMsg(Multiply("18750", "2180262404997607"))
or even:
call BJDebugMsg(Multiply("4200", "518986528207"))
I just get red 'DebugMsg' saying:
And, hm, Where's the problem in this? Am I doing something wrong? What is op? And what limit? Any way to still do that multiplying?
(yarr, too many questions, I know)
JASS:
set i = var1 * 2180262404997607 + var2 * 518986528207 + var3 * 123538807 + var4 * 29407 + var5 * 7 + var6
var1 is [1;18750]
var2,var3,var4,var5 are [1;4200]
So in the end I may get something like
JASS:
set i = 18750 * 2180262404997607 + 4200 * 518986528207 + 4200 * 123538807 + 4200 * 29407 + 4200 * 7 + 6
... which, as I said, WE can't handle
Well, so I made 2 functions -- 'Add' and 'Multiply' that take strings, work with numbers from 0-19 and work perfectly with 'normal' numbers (tho they should work with huge numbers like mine):
JASS:
function Add takes string s1, string s2 returns string
local integer i = 0
local integer n = 0
local integer ii
local string ret = ""
//s1 >= s2 ... if needed change their places, bj_lastPlayedMusic isn't used anywhere
if StringLength(s2) > StringLength(s1) then
set bj_lastPlayedMusic = s2
set s2 = s1
set s1 = bj_lastPlayedMusic
endif
//make the numbers with the same length, adding '0'-s in the beginning
set s1 = "0" + s1
loop
exitwhen StringLength(s1) == StringLength(s2)
set s2 = "0" + s2
endloop
set ii = StringLength(s1)
//add
loop
set n = S2I(SubString(s1,ii-1,ii)) + S2I(SubString(s2,ii-1,ii)) + i
if n >= 10 then
set ret = I2S(n - 10) + ret
set i = 1
else
set ret = I2S(n) + ret
set i = 0
endif
set ii = ii-1
exitwhen ii == 0
endloop
//remove the '0' if it is still there
if SubString(ret,0,1) == "0" then
set ret = SubString(ret,1,StringLength(ret))
endif
return ret
endfunction
Well, multiplying numbers like 5324 and 9812 works perfectly using these functions ... but! When I do something like:
call BJDebugMsg(Multiply("18750", "2180262404997607"))
or even:
call BJDebugMsg(Multiply("4200", "518986528207"))
I just get red 'DebugMsg' saying:
Hit op limit in
Add(106392238282435, 518986528207)
Multiply(4200, 518986528207)
Say_Actions()
And, hm, Where's the problem in this? Am I doing something wrong? What is op? And what limit? Any way to still do that multiplying?
(yarr, too many questions, I know)