delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/01/15:51:52

Date: Sun, 1 Feb 1998 19:55:26 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Guy Rauscher <rauscher AT netvision DOT net DOT il>
cc: djgpp AT delorie DOT com
Subject: Re: Floating point exception question.
In-Reply-To: <34D25AEE.1A79@netvision.net.il>
Message-ID: <Pine.SUN.3.91.980201195505.16390N@is>
MIME-Version: 1.0

On Fri, 30 Jan 1998, Guy Rauscher wrote:

> So, if I have two numbers I want to multiply, how can I forsee the
> exception and prevent it?

How about the following:

    #include <float.h>
    ...
    double a, b, c;

    if (a > DBL_MAX / b)
       throw_error ("a * b overflows, cannot multiply");
    else
       c = a * b;

I suggest to look at the header float.h, there are some quite useful
constants there, besides DBL_MAX.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019