[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] sinf/sin problems
From: |
Lee Duhem |
Subject: |
Re: [Tinycc-devel] sinf/sin problems |
Date: |
Wed, 24 Dec 2014 16:46:14 +0800 |
On Wed, Dec 24, 2014 at 10:08 AM, Oleg N. Cher <address@hidden> wrote:
> Hi all,
>
> float version sinf does not work as expected:
>
> #include <stdio.h>
> #include <math.h>
>
> int main(int argc, char **argv) {
> float f = sinf(0.1);
> printf("%f", f);
> return 0;
> }
>
>>tcc testsinf.c
> tcc: error: undefined symbol 'sinf'
`sinf' is defined in libm.so, you need to link with it. So try this:
tcc testsinf.c -lm
> Next question is a very evil problem, I think. if #include <Math> not
> specified, absolutely no bugs/warnings,
-Wall will give you the warning that you expected.
> but code works wrong:
The code is, sort of, right, your expectation of what it should do is
wrong.
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. That why it only prints "0.000000".
Add `#include <math.h>' should fix this problem.
Sincerely,
lee
>
>
> #include <stdio.h>
>
> int main(int argc, char **argv) {
>
> printf("\n%f", sin(-3.0));
> printf("\n%f", sin(-2.0));
> printf("\n%f", sin(-1.0));
> printf("\n%f", sin(0.0));
> printf("\n%f", sin(1.0));
> printf("\n%f", sin(2.0));
> printf("\n%f", sin(3.0));
> printf("\n%f", sin(3.1415926));
>
> return 0;
> }
>
>>tcc testsinf.c
>>testsinf.exe
>
> 0.000000
> 0.000000
> 0.000000
> 0.000000
> 0.000000
> 0.000000
> 0.000000
> 0.000000
>
> Please agree with me that this must be fixed.
>
> Thank you.
>
>
> --
> Oleg
>
> _______________________________________________
> Tinycc-devel mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
- Re: [Tinycc-devel] TCC as default compiler, (continued)
- Re: [Tinycc-devel] TCC as default compiler, Daniel Glöckner, 2014/12/09
- Re: [Tinycc-devel] TCC as default compiler, cbdev, 2014/12/09
- Re: [Tinycc-devel] TCC as default compiler, stephen Turner, 2014/12/09
- Re: [Tinycc-devel] TCC as default compiler, stephen Turner, 2014/12/09
- Re: [Tinycc-devel] TCC as default compiler, stephen Turner, 2014/12/09
- Re: [Tinycc-devel] TCC as default compiler, stephen Turner, 2014/12/09
- [Tinycc-devel] sinf/sin problems, Oleg N. Cher, 2014/12/23
- Re: [Tinycc-devel] sinf/sin problems, Mads, 2014/12/24
- Re: [Tinycc-devel] sinf/sin problems, Aharon Robbins, 2014/12/24
- Re: [Tinycc-devel] sinf/sin problems,
Lee Duhem <=
- Re: [Tinycc-devel] sinf/sin problems, Daniel Glöckner, 2014/12/24
- Re: [Tinycc-devel] sinf/sin problems, Lee Duhem, 2014/12/26