Page 2 of 3

Re: math.floor()

Posted: Wed Oct 06, 2010 11:09 am
by vrld
zac352 wrote:If you had any idea how base 2 is stored in the memory, you'd know why that happens. :P
If you had any idea how that is total nonsense, you'd know why you should shut up.

Re: math.floor()

Posted: Wed Oct 06, 2010 11:37 am
by zac352
giniu wrote:
zac352 wrote:If you had any idea how base 2 is stored in the memory, you'd know why that happens. :P
it's just how floor and ceil are defined mathematically and not related to how it is stored - it's like saying that sky is blue because of rgb representation in computer, really. Just stick to definition from any (elementary I guess) school math book you might have avoided in past - or wikipedia page linked in third post.
You don't know what you're talking about...
char starts at 00000000, and ends at 11111111.
unsigned char starts at 00000000, and ends at 11111111.
char starts at -128, and ends at 127.
unsigned char starts at 0, and ends at 255.

The first byte is used as the negative sign, and is just subtracted.
Add 2^num_bits/2 to your number to see its unsigned equivalent.
Lua, I believe, has 4 bytes allocated to whole number storage. Not comlpetely sure.
Floor cuts the decimal point numbers off the base 2 end.

You all need to stop acting like base 2 doesn't exist... :ehem:

Re: math.floor()

Posted: Wed Oct 06, 2010 11:45 am
by vrld
zac352 wrote:Add 2^num_bits/2 to your number to see its unsigned equivalent.
Lua, I believe, has 4 bytes allocated to whole number storage. Not comlpetely sure.
Floor cuts the decimal point numbers off the base 2 end.
I'll let you respond to that yourself:
zac352 wrote:You don't know what you're talking about...
With your ignorance you simply can't afford that arrogance.

Re: math.floor()

Posted: Wed Oct 06, 2010 11:57 am
by zac352
vrld wrote:
zac352 wrote:Add 2^num_bits/2 to your number to see its unsigned equivalent.
Lua, I believe, has 4 bytes allocated to whole number storage. Not comlpetely sure.
Floor cuts the decimal point numbers off the base 2 end.
I'll let you respond to that yourself:
zac352 wrote:You don't know what you're talking about...
With your ignorance you simply can't afford that arrogance.
I'm not trying to start a flame war, only to try to tell you that numbers are stored in memory in base 2 [s]why floor works like that[/s]...

Re: math.floor()

Posted: Wed Oct 06, 2010 12:25 pm
by kikito
zac352, you have a tendency speak down to people, specially when you are on shaky grounds yourself. On this forum, asking things politely is ok. Ego-posts don't work particularly well. You should have noticed by now.

If you meant to make a joke (which are, by the way, quite used on these forums) it didn't sound like one. No one is amused.

And giniu, I expected more from you.

Now you both shake your hands and write 10 times an Arkanoid clone on the blackboard.

Now coming back on topic: What zac352 got wrong is that floats are completely separated from integers. Their memory representation and operations are waaay different. Lua uses IEE 754 for representing floats in memory.

Basically, floats have a "significand" part, that works similarly to integers, as well as an "exponent" part. The magnitude of a float number is calculated operating on those both parts at the same time.

This allows storing a bigger range of a number than if you only had one bit per base 2 digits (exponents allow 16-bits floats range to be from 10^-14 to 10^15). The trade-off is an increasing loss of precision, the bigger the exponents are. Also, operations with floats get much more complicated than their integer counterparts. Consider that a simple operation such as adding two floats has to cope with the fact that these floats can have completely different exponents.

This complication also extends to the float-to-integer conversion.

The point is that floats are represented rather differently from integers. math.floor is not just a matter of "cutting the decimal numbers of the base 2 field off" as zac352 believes.

If that helps, making that mistake is very common among newcomers.

Re: math.floor()

Posted: Wed Oct 06, 2010 12:45 pm
by zac352
kikito wrote:zac352, you have a tendency speak down to people, specially when you are on shaky grounds yourself. On this forum, asking things politely is ok. Ego-posts don't work particularly well. You should have noticed by now.

If you meant to make a joke (which are, by the way, quite used on these forums) it didn't sound like one. No one is amused.

And giniu, I expected more from you.

Now you both shake your hands and write 10 times an Arkanoid clone on the blackboard.

Now coming back on topic: What zac352 got wrong is that floats are completely separated from integers. Their memory representation and operations are waaay different. Lua uses IEE 754 for representing floats in memory.

Basically, floats have a "significand" part, that works similarly to integers, as well as an "exponent" part. The magnitude of a float number is calculated operating on those both parts at the same time.

This allows storing a bigger range of a number than if you only had one bit per base 2 digits (exponents allow 16-bits floats range to be from 10^-14 to 10^15). The trade-off is an increasing loss of precision, the bigger the exponents are. Also, operations with floats get much more complicated than their integer counterparts. Consider that a simple operation such as adding two floats has to cope with the fact that these floats can have completely different exponents.

This complication also extends to the float-to-integer conversion.

The point is that floats are represented rather differently from integers. math.floor is not just a matter of "cutting the decimal numbers of the base 2 field off" as zac352 believes.

If that helps, making that mistake is very common among newcomers.
Sowwy. :(
I didn't read over the Lua source code like you did. XD

Re: math.floor()

Posted: Wed Oct 06, 2010 12:47 pm
by zac352
Is this textbox glitch I keep getting when quoting large posts a problem with IE on these computers? I don't get this issue on Firefox at home... :o:

Re: math.floor()

Posted: Wed Oct 06, 2010 12:50 pm
by zac352
Now I feel like all that stuff I learned in that C++ tutorial is a lie. >_>

Re: math.floor()

Posted: Wed Oct 06, 2010 12:59 pm
by kikito
zac352 wrote:I didn't read over the Lua source code like you did. XD
I didn't. I just googled 'Lua floating point'.

Re: math.floor()

Posted: Wed Oct 06, 2010 1:22 pm
by zac352
kikito wrote:
zac352 wrote:I didn't read over the Lua source code like you did. XD
I didn't. I just googled 'Lua floating point'.
That was a joke. ._.