[Solved] Differentiating 32 bits from 64 bits

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
HugoBDesigner
Party member
Posts: 403
Joined: Mon Feb 24, 2014 6:54 pm
Location: Above the Pocket Dimension
Contact:

[Solved] Differentiating 32 bits from 64 bits

Post by HugoBDesigner »

Hello again! I'm making a maths program that deals with large numbers, and because of that I needed to know whether one's computer was 32 bits or 64 bits, so that way I can set myself the limit of the maximum value a number can reach. Is there a way of doing that via LÖVE or even just plain Lua?
Last edited by HugoBDesigner on Sun Sep 11, 2016 12:14 am, edited 1 time in total.
@HugoBDesigner - Twitter
HugoBDesigner - Blog
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Differentiating 32 bits from 64 bits

Post by pgimeno »

You don't need to check the architecture if you want to know what's the maximum number you can store with LÖVE.

In the default Lua, LuaJIT and LÖVE distributions, numbers are always double-precision floating-point numbers. These are always 64-bit wide in any architecture. That includes the exponent, but the mantissa, which is what dictates the maximum consecutive integer you can store, is 53 bits (one of which is implicit, thus not stored in the number).

The last consecutive integer you can store in LÖVE and in the default Lua and LuaJIT distribution is 2^53 = 9007199254740992, which means that the first integer that can't be represented is 2^53+1 = 9007199254740993.

The last number you can store is approximately 1.7976931348623157*10^308. As you get away from zero, the gap between floating point numbers grows.

Lua can be compiled to use other types for its number, though. But I'm not sure if doing that with LÖVE is possible without breaking anything.

(Edited because I wrote the wrong max integers, sorry)
Last edited by pgimeno on Sun Sep 11, 2016 1:42 am, edited 1 time in total.
User avatar
HugoBDesigner
Party member
Posts: 403
Joined: Mon Feb 24, 2014 6:54 pm
Location: Above the Pocket Dimension
Contact:

Re: [Solved] Differentiating 32 bits from 64 bits

Post by HugoBDesigner »

Woah, I wrote a reply here but must have forgotten to send:

Thanks, pgimeno, for you reply! In fact, it seems like my problem is going to have a much simpler solution than what I was expecting!
@HugoBDesigner - Twitter
HugoBDesigner - Blog
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: [Solved] Differentiating 32 bits from 64 bits

Post by bartbes »

And whether a processor is 32-bit or 64-bit does not affect the values it can calculate with, 32-bit processors can do 64-bit calculations and vice versa.
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: [Solved] Differentiating 32 bits from 64 bits

Post by pgimeno »

Well, while that is true, it's also true that for performance reasons, most programs (including some language interpreters) are written in such a way that they use the native integer type of the platform. PHP, for example, does that. Lua can be compiled to do that as well, even though default Lua is safe because it uses FP instead of integers.

Even LÖVE does that at some obscure points. As an extreme example, if you do this in 0.9:

Code: Select all

love.physics.setMeter(5e9); print(love.physics.getMeter())
you will get different results depending on whether the architecture is 32 or 64 bits. Not that you would do that in normal code, of course.

Anyway, to answer the OP's question, if you ever need to know the architecture, which is likely to be never, you can use jit.arch.
Post Reply

Who is online

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