64 bit integers

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

64 bit integers

Martin, Marcus

How do I use 64 bit integers in Lua? By default on my system (VS 2005, WinXP) I get 32 bit integers. Do I need to recompile the entire library with 64 bit support? That would make all integers 64 bit right? Is there a mixed mode?

 

Can anyone point me at some documentation for this issue?

 

Marcus

Reply | Threaded
Open this post in threaded view
|

Re: 64 bit integers

Javier Guerra Giraldez
On Mon, Jun 1, 2009 at 11:59 AM, Martin, Marcus <[hidden email]> wrote:
> How do I use 64 bit integers in Lua? By default on my system (VS 2005,
> WinXP) I get 32 bit integers. Do I need to recompile the entire library with
> 64 bit support? That would make all integers 64 bit right? Is there a mixed
> mode?

by default you don't get integers, the 'Number' type is a double (64
bit, IIRC).  it has enough precision to express 52 bit integers

--
Javier
Reply | Threaded
Open this post in threaded view
|

RE: 64 bit integers

Martin, Marcus
Ah, yes, you are correct. Unfortunately I need the full 64 bit integer size in Lua. How do I get that?

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Javier Guerra
Sent: Monday, June 01, 2009 1:07 PM
To: Lua list
Subject: Re: 64 bit integers

On Mon, Jun 1, 2009 at 11:59 AM, Martin, Marcus <[hidden email]> wrote:
> How do I use 64 bit integers in Lua? By default on my system (VS 2005,
> WinXP) I get 32 bit integers. Do I need to recompile the entire library with
> 64 bit support? That would make all integers 64 bit right? Is there a mixed
> mode?

by default you don't get integers, the 'Number' type is a double (64
bit, IIRC).  it has enough precision to express 52 bit integers

--
Javier

Reply | Threaded
Open this post in threaded view
|

Re: 64 bit integers

Sam Roberts
In reply to this post by Martin, Marcus
On Mon, Jun 1, 2009 at 9:59 AM, Martin, Marcus <[hidden email]> wrote:
> How do I use 64 bit integers in Lua? By default on my system (VS 2005,
> WinXP) I get 32 bit integers. Do I need to recompile the entire library with
> 64 bit support? That would make all integers 64 bit right? Is there a mixed
> mode?

You've a few options. Usually you're using 64bit ints for some
particular purpose (SHA-1 hash IDs, for example), and it's best to
make a userdata that wraps that thing. You can also make a 64-bit int
userdata type, but it won't be a full number in terms of lua
operators, and such.

It is also possible to recompile lua, possibly patched, with the
number type redefined to be a 64-bit int. But then you better not have
code that uses floats... I wouldn't go this route unless you are using
to lua to build a language for an environment where you really, really
want to do lots of 64-bit math. For one  thing, while lua makes this
possible, you are basically spinning a language variant, and might
have troubles using 3rd party libs (if you care).

Searching the lua wiki and mailing list will get lots of hits on this
topic, btw.

Sam
Reply | Threaded
Open this post in threaded view
|

Re: 64 bit integers

Joseph Stewart
In reply to this post by Martin, Marcus
Check this list for Asko's LNUM patch (it's probably in Luaforge too).
It might be exactly what you're looking for.

-joe

On Mon, Jun 1, 2009 at 1:17 PM, Martin, Marcus <[hidden email]> wrote:

> Ah, yes, you are correct. Unfortunately I need the full 64 bit integer size in Lua. How do I get that?
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf Of Javier Guerra
> Sent: Monday, June 01, 2009 1:07 PM
> To: Lua list
> Subject: Re: 64 bit integers
>
> On Mon, Jun 1, 2009 at 11:59 AM, Martin, Marcus <[hidden email]> wrote:
>> How do I use 64 bit integers in Lua? By default on my system (VS 2005,
>> WinXP) I get 32 bit integers. Do I need to recompile the entire library with
>> 64 bit support? That would make all integers 64 bit right? Is there a mixed
>> mode?
>
> by default you don't get integers, the 'Number' type is a double (64
> bit, IIRC).  it has enough precision to express 52 bit integers
>
> --
> Javier
>
>
Reply | Threaded
Open this post in threaded view
|

Re: 64 bit integers

Asko Kauppi
In reply to this post by Martin, Marcus

http://luaforge.net/frs/?group_id=214&release_id=1341

- apply the patch
- compile with -DLNUM_INT64

You will get a mixed mode double / int64 Lua.

If you only need to store 64-bit values from the C side, have you  
considered using light userdata (storing them as pointers). More often  
than not, that is enough.

-asko


Martin, Marcus kirjoitti 1.6.2009 kello 20:17:

> Ah, yes, you are correct. Unfortunately I need the full 64 bit  
> integer size in Lua. How do I get that?
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]
> ] On Behalf Of Javier Guerra
> Sent: Monday, June 01, 2009 1:07 PM
> To: Lua list
> Subject: Re: 64 bit integers
>
> On Mon, Jun 1, 2009 at 11:59 AM, Martin, Marcus <[hidden email]>  
> wrote:
>> How do I use 64 bit integers in Lua? By default on my system (VS  
>> 2005,
>> WinXP) I get 32 bit integers. Do I need to recompile the entire  
>> library with
>> 64 bit support? That would make all integers 64 bit right? Is there  
>> a mixed
>> mode?
>
> by default you don't get integers, the 'Number' type is a double (64
> bit, IIRC).  it has enough precision to express 52 bit integers
>
> --
> Javier
>