This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
LBPHacker's profile picture

Am I near to the highest number in Lua?!

Started by LBPHacker, 02 April 2013 - 10:40 PM
LBPHacker #1
Posted 03 April 2013 - 12:40 AM
Hey, LBPHacker here, with (as you can expect) a rather strange question:
What is the highest number in Lua? Because I've tried this in the prompt:
73951841171511 + 9288674231451648
and I've got 9362626072623160. Notice that the two numbers above have the ending "11" and "48" and the result has the ending "60". That's definitely not right. So… Maybe these number are so high they make Lua mess up a simple addition? (Yes, I know that both numbers are far higher than the maximum value of an unsigned integer, 4294967295)
theoriginalbit #2
Posted 03 April 2013 - 12:51 AM
Google/Stackoverflow how I love thee…

http://stackoverflow.com/questions/945731/what-is-the-maximum-value-of-a-number-in-lua

is is quite common for calculators to begin getting very large numbers incorrect. it is the downside to them using the double data type in the implementation, after a point in time they start loosing precision. As you can see here is another calculator that has the same problem http://puu.sh/2srDT

EDIT: For the record all I Googled was "largest number in lua" to confirm my theory about the lack of precision.
Edited on 02 April 2013 - 10:53 PM
oeed #3
Posted 03 April 2013 - 12:53 AM
Well…

I'm paraphrasing here, but according to this Stack Overflow question.
Numbers in Lua are doubles, which normally (not to sure about ComputerCraft) is a 64 bit floating point. Therefore it is a 10 bit exponent, equal to 2^1024 or 5.6 x 10^300.
In other words/numbers…
Hmmm… Spotlight is saying NaN (too big). Maybe my graphics can do it… nope.


Well anyway, according to that answer its 5.6 + 299 zeros.

EDIT: Ffff… ninja'd :P/>
theoriginalbit #4
Posted 03 April 2013 - 12:54 AM
Spotlight is saying NaN (too big).
Spotlight did it for me….
LBPHacker #5
Posted 03 April 2013 - 12:55 AM
:D/> OK then, that makes sense…

BTW Typed the addition into Google, thought "let's see what does google calculator do with it" - two things popped up:
1: 9.3626261e+15 (coulda forseen…)
2: My post here (yeah, Google Bots are everywhere on this forum…)

EDIT: Thanks guys, but I'm not THAT noob :D/> I know what a normalized number is.
EDIT2: NaN means not-a-number, not "too big" (no offense)
SuicidalSTDz #6
Posted 03 April 2013 - 12:57 AM
Technically the highest number is not a number at all (inf) :P/>
LBPHacker #7
Posted 03 April 2013 - 12:58 AM
Technically the highest number is not a number at all (inf) :P/>

Umm… IIRC… math.huge?
SuicidalSTDz #8
Posted 03 April 2013 - 01:00 AM
Blah! <_</>

Well, time for School :3 (Hmm,or is it? No it is :D/>)
theoriginalbit #9
Posted 03 April 2013 - 01:02 AM
Ok after getting caught in some nasty recursion between classes I think that LuaJ does use doubles… :P/>


Umm… IIRC… math.huge?
math.huge is 'inf'
oeed #10
Posted 03 April 2013 - 01:04 AM
EDIT2: NaN means not-a-number, not "too big" (no offense)


Spotlight is saying NaN (too big).
Spotlight did it for me….

What did you enter?

EDIT: Thanks guys, but I'm not THAT noob :D/> I know what a normalized number is.
EDIT2: NaN means not-a-number, not "too big" (no offense)


Don't worry, I know :P/>
Time with Javascript has taught me that…
theoriginalbit #11
Posted 03 April 2013 - 01:05 AM
Spotlight did it for me….
What did you enter?

73951841171511 + 9288674231451648

http://puu.sh/2srDT
LBPHacker #12
Posted 03 April 2013 - 01:05 AM
math.huge is 'inf'
Yeah, I was talking about inf…


Technically the highest number is not a number at all (inf) :P/>

Umm… IIRC… math.huge?
Brandhout #13
Posted 03 April 2013 - 04:46 AM
Just rambling here, but Lua is build using C right?

C has an integer type, which does not have addition issues of the type above.

According to the lua reference manual, lua code can call C functions. And quickly googleing lua and integer type gives quite a few hits, of people trying to define integers in lua. So you could try to define integers in lua or maybe use a C function….

Don't pin me on any of this, I come from C++ and I don't have too much knowledge about lua (yet).
LBPHacker #14
Posted 03 April 2013 - 04:49 AM
I think CC Lua is sandboxed enough to make me totally unable to call C++ functions (and by the way, CC Lua is based on LuaJ - that J on the end means Java).
Sammich Lord #15
Posted 03 April 2013 - 04:49 AM
Just rambling here, but Lua is build using C right?

C has an integer type, which does not have addition issues of the type above.

According to the lua reference manual, lua code can call C functions. And quickly googleing lua and integer type gives quite a few hits, of people trying to define integers in lua. So you could try to define integers in lua or maybe use a C function….

Don't pin me on any of this, I come from C++ and I don't have too much knowledge about lua (yet).
Lua is originally in C. But CC is using LuaJ which messes with a lot of things.