public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* bug in float on Pentium
@ 2001-04-13 23:23 Joe
  2001-04-14  2:57 ` Alan Cox
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Joe @ 2001-04-13 23:23 UTC (permalink / raw)
  To: linux-kernel

Not sure but I think I found a NEW bug.

I know that there have been some issues with pentiums and floating point
arrithmatic, but this takes the cake...

Linux Lserver.org 2.2.18 #43 SMP Fri Mar 9 14:19:41 EST 2001 i586
unknown

>kgcc --version
egcs-2.91.66

RH 6.2.x / 7.0

try this program

#include <stdio.h>

int main() {

    char tmpx[100];
 char tmpy[100];

 double x = 5483.99;
 float y = 5483.99;

    sprintf (tmpx, "%f",x );
    sprintf (tmpy, "%f",y );

 printf ("%s\n%s\n", tmpx, tmpy);
 return 0;
}


I am getting the following as output

joeja@Lserver$ ./testf
5483.990000
5483.990234


what is with the .990234??  it should be .990000

any ideas on this??

--
Joe Acosta ........
home: joeja@mindspring.com




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: bug in float on Pentium
  2001-04-13 23:23 bug in float on Pentium Joe
@ 2001-04-14  2:57 ` Alan Cox
  2001-04-14  3:01 ` Jakob Østergaard
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Alan Cox @ 2001-04-14  2:57 UTC (permalink / raw)
  To: joeja; +Cc: linux-kernel

> Not sure but I think I found a NEW bug.
> I know that there have been some issues with pentiums and floating point
> arrithmatic, but this takes the cake...

Hardly. Floats are inaccurate.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: bug in float on Pentium
  2001-04-13 23:23 bug in float on Pentium Joe
  2001-04-14  2:57 ` Alan Cox
@ 2001-04-14  3:01 ` Jakob Østergaard
  2001-04-14  5:35 ` Jonathan Morton
  2001-04-15  6:02 ` Matt Billenstein
  3 siblings, 0 replies; 5+ messages in thread
From: Jakob Østergaard @ 2001-04-14  3:01 UTC (permalink / raw)
  To: Joe; +Cc: linux-kernel

On Fri, Apr 13, 2001 at 07:23:24PM -0400, Joe wrote:
> Not sure but I think I found a NEW bug.
> 
> I know that there have been some issues with pentiums and floating point
> arrithmatic, but this takes the cake...
> 
> Linux Lserver.org 2.2.18 #43 SMP Fri Mar 9 14:19:41 EST 2001 i586
> unknown
> 
...
> 
> 
> I am getting the following as output
> 
> joeja@Lserver$ ./testf
> 5483.990000
> 5483.990234
> 
> 
> what is with the .990234??  it should be .990000
> 
> any ideas on this??
> 

Your second number is a 32-bit float - which has roughly 7 digits of
precision.   Just like your program output clearly shows.

(I do however fail to see the relevance of this to linux-kernel)

-- 
................................................................
:   jakob@unthought.net   : And I see the elder races,         :
:.........................: putrid forms of man                :
:   Jakob Østergaard      : See him rise and claim the earth,  :
:        OZ9ABN           : his downfall is at hand.           :
:.........................:............{Konkhra}...............:

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: bug in float on Pentium
  2001-04-13 23:23 bug in float on Pentium Joe
  2001-04-14  2:57 ` Alan Cox
  2001-04-14  3:01 ` Jakob Østergaard
@ 2001-04-14  5:35 ` Jonathan Morton
  2001-04-15  6:02 ` Matt Billenstein
  3 siblings, 0 replies; 5+ messages in thread
From: Jonathan Morton @ 2001-04-14  5:35 UTC (permalink / raw)
  To: joeja, linux-kernel

> double x = 5483.99;
> float y = 5483.99;

>5483.990000
>5483.990234

Well, duh.  Floats are less accurate than doubles, so what?  Read your C
textbook again.

--------------------------------------------------------------
from:     Jonathan "Chromatix" Morton
mail:     chromi@cyberspace.org  (not for attachments)
big-mail: chromatix@penguinpowered.com
uni-mail: j.d.morton@lancaster.ac.uk

The key to knowledge is not to rely on people to teach you it.

Get VNC Server for Macintosh from http://www.chromatix.uklinux.net/vnc/

-----BEGIN GEEK CODE BLOCK-----
Version 3.12
GCS$/E/S dpu(!) s:- a20 C+++ UL++ P L+++ E W+ N- o? K? w--- O-- M++$ V? PS
PE- Y+ PGP++ t- 5- X- R !tv b++ DI+++ D G e+ h+ r++ y+(*)
-----END GEEK CODE BLOCK-----



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: bug in float on Pentium
  2001-04-13 23:23 bug in float on Pentium Joe
                   ` (2 preceding siblings ...)
  2001-04-14  5:35 ` Jonathan Morton
@ 2001-04-15  6:02 ` Matt Billenstein
  3 siblings, 0 replies; 5+ messages in thread
From: Matt Billenstein @ 2001-04-15  6:02 UTC (permalink / raw)
  To: joeja, linux-kernel

It's not that you found a new bug or that floats are inaccurate (they are
just less exact than doubles)...  For example, if you make your program
print some more digits, you'll get:

5483.98999999999978172127157449722290039062500000000000
5483.99023437500000000000000000000000000000000000000000

#include <stdio.h>

int main() {

    unsigned int *X;
    unsigned int *Y;

 double x = 5483.99;
 float  y = 5483.99;

    X = (unsigned int *)&x;
    Y = (unsigned int *)&y;

 printf ("%60.50lf\n%60.50f\n", x, y);

 printf("%lf %x%x %f %x\n", x, X[1], X[0], y, *Y);
 return 0;
}

which you can verify by hand:

5483.990000 40b56bfd70a3d70a
0 10000001011 1.0101 0110 1011 1111 1101 0111 0000 1010 0011 1101 0111 0000
1010
+    2^12   * 1.3388647460937499467092948179925 =
5483.989999999999781721271574497222900390625

5483.990234 45ab5fec
0 10001011  1.010 1011 0101 1111 1110 1100
+   2^12  * 1.338864803314208984375 = 5489.990234375

check out:
http://www.psc.edu/general/software/packages/ieee/ieee.html

l8r

m


Matt Billenstein
mbillens (at) one (dot) net
http://w3.one.net/~mbillens/


----- Original Message -----
From: "Joe" <joeja@mindspring.com>
To: <linux-kernel@vger.kernel.org>
Sent: Friday, April 13, 2001 7:23 PM
Subject: bug in float on Pentium


| Not sure but I think I found a NEW bug.
|
| I know that there have been some issues with pentiums and floating point
| arrithmatic, but this takes the cake...
|
| Linux Lserver.org 2.2.18 #43 SMP Fri Mar 9 14:19:41 EST 2001 i586
| unknown
|
| >kgcc --version
| egcs-2.91.66
|
| RH 6.2.x / 7.0
|
| try this program
|
| #include <stdio.h>
|
| int main() {
|
|     char tmpx[100];
|  char tmpy[100];
|
|  double x = 5483.99;
|  float y = 5483.99;
|
|     sprintf (tmpx, "%f",x );
|     sprintf (tmpy, "%f",y );
|
|  printf ("%s\n%s\n", tmpx, tmpy);
|  return 0;
| }
|
|
| I am getting the following as output
|
| joeja@Lserver$ ./testf
| 5483.990000
| 5483.990234
|
|
| what is with the .990234??  it should be .990000
|
| any ideas on this??
|
| --
| Joe Acosta ........
| home: joeja@mindspring.com
|
|
|
| -
| To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
| the body of a message to majordomo@vger.kernel.org
| More majordomo info at  http://vger.kernel.org/majordomo-info.html
| Please read the FAQ at  http://www.tux.org/lkml/


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-04-15  6:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-04-13 23:23 bug in float on Pentium Joe
2001-04-14  2:57 ` Alan Cox
2001-04-14  3:01 ` Jakob Østergaard
2001-04-14  5:35 ` Jonathan Morton
2001-04-15  6:02 ` Matt Billenstein

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox