math.floor()

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: math.floor()

Post 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.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: math.floor()

Post 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:
Hello, I am not dead.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: math.floor()

Post 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.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: math.floor()

Post 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]...
Hello, I am not dead.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: math.floor()

Post 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.
When I write def I mean function.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: math.floor()

Post 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
Hello, I am not dead.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: math.floor()

Post 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:
Hello, I am not dead.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: math.floor()

Post by zac352 »

Now I feel like all that stuff I learned in that C++ tutorial is a lie. >_>
Hello, I am not dead.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: math.floor()

Post 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'.
When I write def I mean function.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: math.floor()

Post 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. ._.
Hello, I am not dead.
Locked

Who is online

Users browsing this forum: Ahrefs [Bot] and 50 guests