Thread: Re: [GENERAL] division by zero

Re: [GENERAL] division by zero

From
Tom Lane
Date:
"Eric B. Ridge" <ebr@tcdi.com> writes:
> select 1/0; fails as expected on my x86 Linux box, so yer right, it's
> just my little Mac.  "I switched because Mac's can divide by zero."

I checked into this, and indeed OS X 10.2 is behaving funny: integer
divide by zero doesn't raise any signal, it just returns a bogus answer.
They're within their rights to do so according to the ANSI C spec
(wherein division by zero is stated to have undefined behavior).
But since other BSD-derived Unixen all seem to raise SIGFPE, I can't
help wondering if this shouldn't be considered a bug.

I think we have three possible responses:

1. Put explicit tests for zero into the integer division SQL function
routines.

2. Consider this Apple's problem and file a bug report.

3. Both.

I don't care for answer #1 alone, because it would only catch zero
divides in the specific places we put in tests; internal errors would
likely go uncaught.  So I think a complaint to Apple is in order.
I'm not sure whether to also put in zero-divide guards.  Comments?

            regards, tom lane

Re: [GENERAL] division by zero

From
Stephan Szabo
Date:
On Sat, 8 Mar 2003, Tom Lane wrote:

> "Eric B. Ridge" <ebr@tcdi.com> writes:
> > select 1/0; fails as expected on my x86 Linux box, so yer right, it's
> > just my little Mac.  "I switched because Mac's can divide by zero."
>
> I checked into this, and indeed OS X 10.2 is behaving funny: integer
> divide by zero doesn't raise any signal, it just returns a bogus answer.
> They're within their rights to do so according to the ANSI C spec
> (wherein division by zero is stated to have undefined behavior).
> But since other BSD-derived Unixen all seem to raise SIGFPE, I can't
> help wondering if this shouldn't be considered a bug.
>
> I think we have three possible responses:
>
> 1. Put explicit tests for zero into the integer division SQL function
> routines.
>
> 2. Consider this Apple's problem and file a bug report.
>
> 3. Both.
>
> I don't care for answer #1 alone, because it would only catch zero
> divides in the specific places we put in tests; internal errors would
> likely go uncaught.  So I think a complaint to Apple is in order.
> I'm not sure whether to also put in zero-divide guards.  Comments?

We probably should put in guards since relying on sane behavior for
division by zero is probably unsafe from a portability standpoint.  This
could hide some internal error on a system that has this problem (since we
could otherwise put it into a regression test) but those systems are
currently broken if the internal error occurs anyway.


Re: [GENERAL] division by zero

From
Justin Clift
Date:
Tom Lane wrote:
<snip>
> 2. Consider this Apple's problem and file a bug report.

Is there a good place to report errors to Apple for this kind of thing?

Was chatting to one of the guys in the MacOSX development team at Apple 
a while ago and can pursue it through there if needed.

:-)

Regards and best wishes,

Justin Clift


> 3. Both.
> 
> I don't care for answer #1 alone, because it would only catch zero
> divides in the specific places we put in tests; internal errors would
> likely go uncaught.  So I think a complaint to Apple is in order.
> I'm not sure whether to also put in zero-divide guards.  Comments?
> 
>             regards, tom lane


-- 
"My grandfather once told me that there are two kinds of people: those
who work and those who take the credit. He told me to try to be in the
first group; there was less competition there."
- Indira Gandhi



Re: [GENERAL] division by zero

From
Eric B.Ridge
Date:
On Saturday, March 8, 2003, at 11:54  PM, Justin Clift wrote:

> Tom Lane wrote:
> <snip>
>> 2. Consider this Apple's problem and file a bug report.
>
> Is there a good place to report errors to Apple for this kind of thing?

The best place I can find is:  
http://developer.apple.com/bugreporter/index.html

Unfortunately, there doesn't seem to be a way to query existing 
reports... If there is, I can't find it.

Also, I can't help but wonder why Apple/DarwinTeam handle integer 
division by zero this way.  There must be a reason, which makes me 
think that "[considering] this Apple's problem" might not work out for 
postgres in the end.

eric



Re: [GENERAL] division by zero

From
Justin Clift
Date:
Hi guys,

Was just looking around Google for similar reports of errors and came 
across this:

MacOS X Server Developer Release Notes: Core OS Runtime
http://www.geminisolutions.com/WebObjects_4.5/Documentation/Developer/YellowBox/ReleaseNotes/Runtime.html

Looks like this is a known problem (as of 1998) and may not have been fixed.

Further hits come up when searching on the Apple Developer Connection 
site too:


http://developer.apple.com/cgi-bin/search.pl?&q=divide+by+zero&num=10&lang=lang_en|lang_zh-CN|lang_fr|lang_de|lang_ja&ie=utf8&oe=utf8
(that should be all one line)

And this one looks potentially interesting:

http://developer.apple.com/technotes/tn2002/tn2053.html
(search in this page for "FE_ENABLE_DIVBYZERO")

Have asked the member of the Apple MacOS X Server team what he 
recommends the best way to proceed is.

Regards and best wishes,

Justin Clift


Eric B.Ridge wrote:
> On Saturday, March 8, 2003, at 11:54  PM, Justin Clift wrote:
> 
>> Tom Lane wrote:
>> <snip>
>>
>>> 2. Consider this Apple's problem and file a bug report.
>>
>>
>> Is there a good place to report errors to Apple for this kind of thing?
> 
> 
> The best place I can find is:  
> http://developer.apple.com/bugreporter/index.html
> 
> Unfortunately, there doesn't seem to be a way to query existing 
> reports... If there is, I can't find it.
> 
> Also, I can't help but wonder why Apple/DarwinTeam handle integer 
> division by zero this way.  There must be a reason, which makes me think 
> that "[considering] this Apple's problem" might not work out for 
> postgres in the end.
> 
> eric
> 


-- 
"My grandfather once told me that there are two kinds of people: those
who work and those who take the credit. He told me to try to be in the
first group; there was less competition there."
- Indira Gandhi