Linux-kernel mailing list archive 1998-31,: Re: floating-point abuse in 2.1.113

# Re: floating-point abuse in 2.1.113

Richard B. Johnson (root@chaos.analogic.com)
Wed, 5 Aug 1998 14:31:27 -0400 (EDT)

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: Dieter =?ISO-8859-1?Q?N=FCtzel: "2.1.113 Mill I 8MB & scrollback :-("
- Previous message: Peter T. Breuer: "Re: devfs debate"
- In reply to: Albert D. Cahalan: "Re: floating-point abuse in 2.1.113"

On Wed, 5 Aug 1998, Albert D. Cahalan wrote:

> >>>> How can that be a problem? Shouldn't the multiplication and cast
> >>>> be evaluated at compile time, leaving only an int?
>
> > main()
> > {
> > float foo;
> >
> > foo = 1.0 * 1.0 * 1.0;
> > printf("%f\n", foo);
> >
> > }
>
> That's not the same thing at all though. The kernel code
> was more like this:
>
> main(){
> int foo;
> foo = (int) 1.0 * 1.0 * 1.0;
> printf("%d\n", foo);
> }
>
> It makes no sense to leave the floating point in the object file.
> All I can figure is something related to IEEE rounding, in which
> case there ought to be compiler switch to eliminate such concern.
[SNIPPED]

There is apparently some obscure arrangement of parenthesis that
makes gcc handle it the way it does. I can't make gcc do anything
bad with a simple program, i.e.......

#include <stdio.h>
main()
{
int foo;

foo = (int) (1.1 * 1.2 * 1.3 * 1.4);
printf("%d\n", foo);

}
.file "aaa.c"
.version "01.01"
gcc2_compiled.:
.section .rodata
.LC0:
.string "%d\n"
.text
.align 16
.globl main
.type main,@function
main:
pushl %ebp
movl %esp,%ebp
subl $4,%esp
movl $2,-4(%ebp) ; <- Note!
movl -4(%ebp),%eax
pushl %eax
pushl $.LC0
call printf
addl $8,%esp
.L1:
movl %ebp,%esp
popl %ebp
ret
.Lfe1:
.size main,.Lfe1-main
.ident "GCC: (GNU) 2.7.2"

Cheers,
Dick Johnson
***** FILE SYSTEM MODIFIED *****
Penguin : Linux version 2.1.113 on an i586 machine (66.15 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html

- Next message: Dieter =?ISO-8859-1?Q?N=FCtzel: "2.1.113 Mill I 8MB & scrollback :-("
- Previous message: Peter T. Breuer: "Re: devfs debate"
- In reply to: Albert D. Cahalan: "Re: floating-point abuse in 2.1.113"