lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2014-11-18 22:47 GMT+02:00 Robert Virding <rvirding@gmail.com>:
> That is not just a "scripter" problem, I think it is very common that
> programmers don't understand all the peculiarities of floating point. I
> don't know whether having integer data types makes this worse or not.

Tim's example and comment was:
>> >
>> > i = 1<<62
>> > a = 2^62
>> > print(i, a)
>> > i = i * 4
>> > a = a * 4
>> > print(i,a)
>> >
>> > Now, I know what is going on, and you know what is going on. But does
>> > the average scripter know?

It is also very common that programmers don't understand all the
peculiarities of integer overflow and twos complement.

The rule taught to newbies and average scripters should be:
- If you need to measure, put a decimal point in every numeric literal.
- If you need to count, don't put it in.
- If you intend to use the number as a bit pattern, use hexadecimal literals,
   not decimal.

64 bits is a lot when you are counting. For example, the total GDP of
the world, expressed in US cents, easily fits in.