integer overflow vs float overflow

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

integer overflow vs float overflow

aryajur
Hi,
    I see that C wraps integer overflow but float reaches 1.#INF00. C must be doing what the processor implements. Lua 5.3 also wraps integer overflow for float overflow it gives inf. So does Lua check specifically when float overflow happens and substitute inf in place of 1.#INF00?
    If it does is it possible to have integer arithmetic also saturating to inf rather than wrapping to minimum?

Thanks,
Milind

Reply | Threaded
Open this post in threaded view
|

Re: integer overflow vs float overflow

Coda Highland
Lua stores floats in their native format. There is no difference
between a C 1.#INF00 and a Lua inf.

/s/ Adam

On Tue, May 12, 2015 at 5:36 PM, Milind Gupta <[hidden email]> wrote:

> Hi,
>     I see that C wraps integer overflow but float reaches 1.#INF00. C must
> be doing what the processor implements. Lua 5.3 also wraps integer overflow
> for float overflow it gives inf. So does Lua check specifically when float
> overflow happens and substitute inf in place of 1.#INF00?
>     If it does is it possible to have integer arithmetic also saturating to
> inf rather than wrapping to minimum?
>
> Thanks,
> Milind
>

Reply | Threaded
Open this post in threaded view
|

Re: integer overflow vs float overflow

aryajur



On Tue, May 12, 2015 at 5:51 PM, Coda Highland <[hidden email]> wrote:
Lua stores floats in their native format. There is no difference
between a C 1.#INF00 and a Lua inf.

Yes I was already assuming that. I meant was that printf displays 1.#INF00 while lua print displays inf. So does it mean that the print functions are responsible for showing the different outputs rather than the native representation of the large float?
 
Reply | Threaded
Open this post in threaded view
|

Re: integer overflow vs float overflow

Dirk Laurie-2
2015-05-13 2:55 GMT+02:00 Milind Gupta <[hidden email]>:
> On Tue, May 12, 2015 at 5:51 PM, Coda Highland <[hidden email]> wrote:
>>
>> Lua stores floats in their native format. There is no difference
>> between a C 1.#INF00 and a Lua inf.
>>
> Yes I was already assuming that. I meant was that printf displays 1.#INF00
> while lua print displays inf.

My C version (gcc version 4.8.2) displays inf with print format "%.e".
What compiler and print format do you use?

Reply | Threaded
Open this post in threaded view
|

Re: integer overflow vs float overflow

aryajur
I use mingw gcc 4.8.1. using print format %f:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    float a = 1;
    while(1)
    {
        a = a*10;
        printf("a is %f\n",a);
    }
    return 0;
}


On Tue, May 12, 2015 at 11:32 PM, Dirk Laurie <[hidden email]> wrote:
2015-05-13 2:55 GMT+02:00 Milind Gupta <[hidden email]>:
> On Tue, May 12, 2015 at 5:51 PM, Coda Highland <[hidden email]> wrote:
>>
>> Lua stores floats in their native format. There is no difference
>> between a C 1.#INF00 and a Lua inf.
>>
> Yes I was already assuming that. I meant was that printf displays 1.#INF00
> while lua print displays inf.

My C version (gcc version 4.8.2) displays inf with print format "%.e".
What compiler and print format do you use?