tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] sinf/sin problems


From: Daniel Glöckner
Subject: Re: [Tinycc-devel] sinf/sin problems
Date: Wed, 24 Dec 2014 13:53:47 +0100
User-agent: Mutt/1.5.20 (2009-06-14)

Hi,

just some nit-picking:

On Wed, Dec 24, 2014 at 04:46:14PM +0800, Lee Duhem wrote:
> `sinf' is defined in libm.so, you need to link with it.

on Linux

> As explained by Aharon, c compiler will offer an implicit declaration
> for any undeclared function that it saw, and the return type of this
> implicit declaration is `int'. Therefore those return values of `sin'
> in your code will be converted to `int' first, then convert to `double'
> for `printf' to print.

The return value of a function returning an int is not passed in the
register where a double would be returned, so you might get garbage
that is in no way related to the input.

On top of that the int is not cast to double in
printf("\n%f", sin(1.0));
The bytes on the stack are simply reinterpreted as double, so
printf("%f\n", 1);
will not print 1.000000.  That's because of the ellipsis in the
declaration of printf.

Best regards,

  Daniel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]