Article View: alt.os.linux.mandrake
Article #521Re: Problems with float variables in C
From: Tim Prince
Date: Sat, 08 Sep 2001 05:42
Date: Sat, 08 Sep 2001 05:42
40 lines
3083 bytes
3083 bytes
"Edward Rosten" <u98ejr@ecs.ox.ac.uk> wrote in message news:clcm-20010907-0010@plethora.net... > > When checking for possible difficulty with division by zero, if you don't > > wish to get into trapping overflow and the like, you should check at least > > for small non-zero numbers. If all your numerators have absolute value < 4, > > you could safely do > > #include <float.h> > > if(fabs(y)>FLT_MIN) > > proceed with division by y > > else > > treat as error > > I'm not trying to be pedantic, I'm genuinely curious, but isn't > > fabs(y) > FLT_MIN > > equivalent to > > f != 0 > > Since 0 can be represented exactly and FLT_MIN is the smallest > possible float greater than zero? > > -Ed > Maybe I didn't explain in enough detail. The x87 register representation of float is long double, with nearly twice as many bits in the exponent as a float will hold when stored to memory. A program could come up with extremely small numbers which might be as good as zero from the point of view of the application, but will not be caught by the comparison with 0. Even if the numbers were not widened in register, subnormal values produced by gradual underflow are smaller than FLT_MIN but non-zero. FLT_MIN would be the smallest float > 0 only when running on an architecture without either extended precision or gradual underflow. Yes, those are coming back, but the OP clearly doesn't have such. -- comp.lang.c.moderated - moderation address: clcm@plethora.net
Technical Details
Message-ID:
<clcm-20010908-0001@plethora.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!nntp.abs.net!news-out.visi.com!hermes.visi.com!gemini.plethora.net.POSTED!not-for-mailReferences:
<clcm-20010905-0003@plethora.net> <clcm-20010905-0016@plethora.net> <clcm-20010907-0010@plethora.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,898a7d80327816b3 X-Google-Attributes: gid11318c,public X-Google-Thread: f8a83,898a7d80327816b3 X-Google-Attributes: gidf8a83,public X-Google-Thread: f65d0,898a7d80327816b3 X-Google-Attributes: gidf65d0,public X-Google-Thread: 100850,77ebfbc06b0f9856 X-Google-Attributes: gid100850,public X-Google-Thread: 108717,898a7d80327816b3 X-Google-Attributes: gid108717,public X-Google-ArrivalTime: 2001-09-07 22:42:13 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!nntp.abs.net!news-out.visi.com!hermes.visi.com!gemini.plethora.net.POSTED!not-for-mail Subject: Re: Problems with float variables in C Approved: clc@plethora.net References: <clcm-20010905-0003@plethora.net> <clcm-20010905-0016@plethora.net> <clcm-20010907-0010@plethora.net> From: "Tim Prince" <tprince@computer.org> X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 Organization: MindSpring Enterprises X-Msmail-priority: Normal X-Priority: 3 X-Server-date: 8 Sep 2001 00:57:45 GMT Return-Path: <news@slb2.atl.mindspring.net> X-Mimeole: Produced By Microsoft MimeOLE V5.50.4133.2400 Newsgroups: alt.os.linux.mandrake,comp.lang.c.moderated,comp.programming,gnu.gcc,gnu.gcc.help Message-ID: <clcm-20010908-0001@plethora.net> Originator: clcm@plethora.net (Comp Lang C'Moderated) Date: 08 Sep 2001 05:42:06 GMT Lines: 40 NNTP-Posting-Host: 24803d54.news.plethora.net X-Trace: 999927726 gemini.plethora.net 326 clcm@205.166.146.1 X-Complaints-To: abuse@plethora.net