🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Bernd Fehling Tue, 19 Nov 1996 00:00
bug report
#6156
Author: Bernd Fehling
Date: Tue, 19 Nov 1996 00:00
42 lines
1700 bytes
Hello,

I think I've found a bug.

I'm using gcc 2.7.2 on LINUX and on Solaris.

Here is my testprogramm:

/* --------------------------------------------------- */
#include <stdio.h>

void main()
{
  double input = 2.01; /* also with 4.02, 8.04, 16.08, ... */
  int result = 0.0;

  input = input * 100.0;
  result = input;
  printf("(Input * 100.0) is: %f,   Result is: %d \n", input, result);
}

/* ---------------------------------------------------- */

What I suppose from this program is, that it should give
me the result of 201. But actually I get a result of 200.
This happens also with 4.02 (401), 8.04 (803) and so on.
This also happens, if the value is negative or only the half 
of 2.01 (1.005 but then you have to multiply with 1000.0).

This will NOT happen if you make 'input' a float variable.

I tried nearly all different compiler switches, but I couldn't
get rid of this problem.

My opinion is, that this is a problem of the compiler, isn't it?

Please mail me your opinion.

regards

Bernd Fehling           EMAIL: befehl@ub.uni-bielefeld.de
Re: bug report
#6157
Author: James Carlson
Date: Tue, 19 Nov 1996 00:00
22 lines
1334 bytes

In article <3291CEEC.777B1579@ub.uni-bielefeld.de>, befehl@ub.uni-bielefeld.de (Bernd Fehling) writes:
[...]
|>   double input = 2.01; /* also with 4.02, 8.04, 16.08, ... */
[...]

2.01 does not have an exact representation standard IEEE base-2 floating
point.

|> My opinion is, that this is a problem of the compiler, isn't it?

Not.  It's normal round-off.

Run, do not walk, to the nearest bookstore and buy any decent book on
numerical analysis.  I recommend Knuth's second volume for the basics,
though it is tough reading for a beginner.

-- 
James Carlson <carlson@xylogics.com>            Tel:  +1 617 272 8140
Annex Interface Development / Xylogics, Inc.          +1 800 225 3317
53 Third Avenue / Burlington MA  01803-4491     Fax:  +1 617 272 2618
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads