delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/12/19/15:40:15

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Variable malfunction?
Date: Sat, 19 Dec 1998 12:23:55 -0800
Organization: Alcyone Systems
Lines: 26
Message-ID: <367C0B5B.44E7A205@alcyone.com>
References: <002301be2b8a$37ab3180$08034ac3 AT oemcomputer>
NNTP-Posting-Host: charmaine.alcyone.com
Mime-Version: 1.0
X-Mailer: Mozilla 3.01 (X11; I; Linux 2.0.34 i686)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id PAB30241
Reply-To: djgpp AT delorie DOT com

Veli-Pekka Kilpeläinen wrote:

> gr = index / 8192 * pi2;        // gr is always zero!

It's because you're letting it use the default order of operations, in
which the division occurs in integer math, and so the result is always
zero, which is them multiplied by a double, promoted to double, but is
still zero.

What you need to do is promote the computation to double early on.  The
easiest way to do this is to make the 8192 constant floating point:

    gr = index/8192.*pi2;

Now to calculate index/8192., index must be promoted to double, and you
get the result that you want.

-- 
Erik Max Francis / email max AT alcyone DOT com / whois mf303 / icq 16063900
Alcyone Systems / irc maxxon (efnet) / finger max AT finger DOT alcyone DOT com
  San Jose, CA / languages En, Eo / web http://www.alcyone.com/max/
          USA / icbm 37 20 07 N 121 53 38 W / &tSftDotIotE
             \
            / All the gods are dead except the god of war.
           / Eldridge Cleaver

- Raw text -


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