R
Ricky
Guest
On Monday, May 2, 2022 at 1:04:34 PM UTC-4, John Larkin wrote:
Or, you can code to handle such cases in a way that is logical, such as not dividing by zero in the first place. A \"trap\" is just the detection of the condition and implies nothing about how it is handled. So it is not inherently bad.
The crash is the sort of behavior that happens when the situation is ignored or handled poorly. Yeah, it\'s always better to not crash. That\'s a bit of a \"Duh!\"
--
Rick C.
-- Get 1,000 miles of free Supercharging
-- Tesla referral code - https://ts.la/richard11209
On Mon, 02 May 2022 11:54:32 -0400, Joe Gwinn <joeg...@comcast.net
wrote:
On Mon, 2 May 2022 15:28:46 +0100, Martin Brown
\'\'\'newspam\'\'\'@nonad.co.uk> wrote:
On 02/05/2022 15:10, jla...@highlandsniptechnology.com wrote:
On Sun, 1 May 2022 20:27:33 -0700 (PDT), whit3rd <whi...@gmail.com
wrote:
On Saturday, April 30, 2022 at 1:23:21 PM UTC-7, legg wrote:
On Sat, 30 Apr 2022 10:47:30 -0700 (PDT), Ricky
gnuarm.del...@gmail.com> wrote:
On Saturday, April 30, 2022 at 12:11:41 PM UTC-4, jla...@highlandsniptechnology.com wrote:
I wrote an s32.32 saturating math package for the 68K that always did
what was most reasonable.
0/0 = 0
I\'m sure no one can explain why 0/0 = 0 makes sense. Zero does not represent just exactly zero. Just as 1 is the range from 1/2 to 1-1/2, zero is the range from -1/2 to +1/2.
If the denominator is not zero, as the numerator approaches zero, yes, in the limit, the result approaches zero. But if the numerator is not zero, as the denominator approaches zero, in the limit, the result approaches infinity. So why would 0/0=0 make sense?
I would have expected 0/0=1 ie no rational difference.
That\'s the case if you consider lim x/x as x approaches zero. But,
what of the limit of 2x/x, or -x/x, as x approaches zero? NAN is the
best way to get a thinking human to understanding what the computer
is trying to express.
What does a control system do when the heater voltage is computed to
be NAN?
Shut down. The situation should never arise if you have scaled the
problem correctly and you should never be dividing by zero anyway.
If the denominator of a division is zero then you haven\'t thought out
the representation of your problem correctly. Testing for zero is
usually quick (and often implicitly available in integer arithmetic).
Umm. Testing for zero doesn\'t necessarily change anything.
I have a war story here. Many decades ago, I was the software
architect for the mission software of a ship self defense system that
shoots incoming cruise missiles down, if it can. From detection at
the horizon to impact on ownship is maybe twenty seconds.
One fine day, a mob of software engineers turned up, locked in
argument about what to do if the engageability calculation suffered a
divide-by-zero exception.
This is not a coding error per se, it\'s a mathematical singularity in
the equations - some engagement geometries will hit the singularity,
and the embedded realtime computers of that day could not handle the
more complicated math needed to avoid such things fast enough to
matter.
There were two schools: Just provide a very large number and proceed,
praying. Stop and print out a bunch of diagnostic information.
Hmm. So the user, an ordinary sailor operating the self-defense
system is in the middle of an engagement with an incoming cruise
missile, and is suddenly handed a bunch or error messages, with less
than twenty seconds to live ... Really??? No! Just silently return
the best answer possible given the situation and press on, praying.
Joe Gwinn
Yes. A best guess is better than an exception trap. Or a crash.
Or, you can code to handle such cases in a way that is logical, such as not dividing by zero in the first place. A \"trap\" is just the detection of the condition and implies nothing about how it is handled. So it is not inherently bad.
The crash is the sort of behavior that happens when the situation is ignored or handled poorly. Yeah, it\'s always better to not crash. That\'s a bit of a \"Duh!\"
--
Rick C.
-- Get 1,000 miles of free Supercharging
-- Tesla referral code - https://ts.la/richard11209