[Solved] Differentiating 32 bits from 64 bits
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- 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
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.
Re: Differentiating 32 bits from 64 bits
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)
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.
- 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
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!
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!
- 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
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.
Re: [Solved] Differentiating 32 bits from 64 bits
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:
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.
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())
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.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], slime and 190 guests