Article View: alt.os.linux.mandrake
Article #507Re: Problems with float variables in C
From: Trevor L. Jackson, III
Date: Sat, 08 Sep 2001 19:10
Date: Sat, 08 Sep 2001 19:10
35 lines
3063 bytes
3063 bytes
Edward Rosten wrote: > > 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? FLT_MIN is not the smallest possible float greater than zero. It is the smallest float with FLT_DIG of valid mantissa digits. Gradual underflow (to zero) may include intermediate values between FLT_MIN and zero that have fewer than FLT_DIG digits of precision. Normalized numbers (>=FLT_MIN) shift the mantissa and scale the exponent until the MSB of the mantissa is one. So called "denormalized numbers" aren't shifted (because there is no room to scale the exponent below FLT_MIN_EXP). The result is a gradual loss of precision as you decrease toward zero. There are typically 2**(FLT_DIG-1)-1 such numbers between FLT_MIN and zero. -- comp.lang.c.moderated - moderation address: clcm@plethora.net
Technical Details
Message-ID:
<clcm-20010908-0005@plethora.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-xfer.siscom.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: 108717,898a7d80327816b3 X-Google-Attributes: gid108717,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-ArrivalTime: 2001-09-08 12:10:59 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-xfer.siscom.net!news-out.visi.com!hermes.visi.com!gemini.plethora.net.POSTED!not-for-mail X-Old-trace: typhoon.ne.mediaone.net 999960095 24.147.52.14 (Sat, 08 Sep 2001 10:41:35 EDT) Subject: Re: Problems with float variables in C Approved: clc@plethora.net Content-Transfer-encoding: 7bit References: <clcm-20010905-0003@plethora.net> <clcm-20010905-0016@plethora.net> <clcm-20010907-0010@plethora.net> From: "Trevor L. Jackson, III" <fullmoon@aspi.net> Organization: Organization X-Accept-language: en Content-Type: text/plain; charset=us-ascii Return-Path: <news@lrnws01.ne.mediaone.net> X-Old-complaints-to: abuse@mediaone.net Mime-Version: 1.0 Newsgroups: alt.os.linux.mandrake,comp.lang.c.moderated,comp.programming,gnu.gcc,gnu.gcc.help Message-ID: <clcm-20010908-0005@plethora.net> X-Mailer: Mozilla 4.72 [en] (WinNT; U) Originator: clcm@plethora.net (Comp Lang C'Moderated) Date: 08 Sep 2001 19:10:53 GMT Lines: 35 NNTP-Posting-Host: f6c03a00.news.plethora.net X-Trace: 999976253 gemini.plethora.net 332 clcm@205.166.146.1 X-Complaints-To: abuse@plethora.net