🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.os.linux.mandrake
Article #517

Re: Problems with float variables in C

#517
From: Tim Prince
Date: Thu, 06 Sep 2001 03:24
40 lines
3078 bytes
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

Depending on your problem, the problem you describe might occur far less
frequently if your variables were declared as double.
All your intermediate float operations will be performed in long double by
default, admitting non-zero working register values as small as LDBL_MIN.
"Rishabh Gupta" <rg117@ohm.york.ac.uk> wrote in message
news:clcm-20010905-0003@plethora.net...
> Hi all,
>     I've been getting really strange results in my program when I use very
> small float values. For example, I check for 0.0 in case of division by
zero
> errors but I still get the error. I also get other strange results
> like -0.0000...... (although I'm guessing that its just not displaying all
> the digits)
> My system is
>     Pentium II 500 Mhz, 128MB
>     Linux Mandrake 8.0
> I have checked my program repeatedly and I can't find anything wrong with
it
> (its not even very complicated). Could the problem be a bug in the
compiler
> (GCC) or is it just supposed to do this?
>
> If anyone can help I would be very greatful.
> Many Thanks!!
>
> Rishabh
> --
> comp.lang.c.moderated - moderation address: clcm@plethora.net
-- 
comp.lang.c.moderated - moderation address: clcm@plethora.net
Technical Details
Message-ID: <clcm-20010905-0016@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-out.visi.com!hermes.visi.com!gemini.plethora.net.POSTED!not-for-mail
References: <clcm-20010905-0003@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-05 20:24:17 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-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>
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: 6 Sep 2001 02:52:27 GMT
Return-Path: <news@slb5.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-20010905-0016@plethora.net>
Originator: clcm@plethora.net (Comp Lang C'Moderated)
Date: 06 Sep 2001 03:24:09 GMT
Lines: 40
NNTP-Posting-Host: 1da7853f.news.plethora.net
X-Trace: 999746649 gemini.plethora.net 320 clcm@205.166.146.1
X-Complaints-To: abuse@plethora.net