[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Unexpected calculation result with Lua53
- From: Rena <hyperhacker@...>
- Date: Sun, 3 May 2015 01:44:32 -0400
On Sun, May 3, 2015 at 1:12 AM, Dirk Laurie <firstname.lastname@example.org> wrote:
> 2015-05-03 3:14 GMT+02:00 Milind Gupta <email@example.com>:
>>> Convert an overflow result to floating point seems tempting, but
>>> we do not see it as a useful/practical option. First, it is quite
>>> expensive to check multiplication overflows in ANSI C. Second, if you
>>> are computing with integers, you probably need a correct result, not a
>>> rough aproximation.
>> I was wondering so does it mean we have to be careful when we use integer
>> number and floating number into our programs? If that is the case wouldn't
>> it be easier if integer type was defined separately allowing its usage
>> explicitly when needed and thought out?
> You always have to be careful when using computer arithmetic
> instead of exact arithmetic. It is true that the results of integer
> overflow tend to to be very dramatic, for example causing a rocket
> destined for space to reverse direction and crash , but the
> results of naive reliance on floating point can be no less disastrous,
> for example causing an anti-missile system to fail .
> In the first case, US$370 million, in the second 28 lives, were lost
> because programmers did not understand computer arithmetic
> In both cases, integer and float, usage should be "thought out".
> Anything that contributes to a false sense of security just makes
> it harder to find bugs already at the design stage. I guess that
> one in every 100 programmers does the kind of work for which
> the distinction between integer and float is so important that the
> "type" function should be overridden . For the sake of the
> other 99, this is not standard in Lua, but that one programmer
> had better do it.
>  http://en.wikipedia.org/wiki/Cluster_(spacecraft)
>  http://en.wikipedia.org/wiki/MIM-104_Patriot#Failure_at_Dhahran
>  I.e. every program should start with the following lines:
> local default_type = type
> type = function(x)
> local T=default_type(x)
> if T=="number" then T=math.type(x) end
> return T
I think Lua is not certified for use in rockets... :-) (but your point
Sent from my Game Boy.