[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] My code doesn't float
From: |
Jim Ursetto |
Subject: |
Re: [Chicken-users] My code doesn't float |
Date: |
Wed, 17 Aug 2011 00:55:12 -0500 |
Better solution is probably to declare these in test1.h and then include it
from stest1.scm via
#> #include "test1.h" <#
and also #include it from test1.c for good measure. Same would be true if you
had implemented stest1 directly in C.
On Aug 17, 2011, at 12:04 AM, Paul Colby wrote:
> Got it,
>
> I finally resorted to clang and got a warning about implicit declarations in
> c compilation.
> Apparently, one needs something to the effect,
>
> (foreign-declare "float testFloat(float);")
> (foreign-declare "double testDouble(double);")
>
> in stest1.scm to tell c that testFloat and it's argument are floats. Well,
> that only took most
> of a day to learn....
>
> On Aug 16, 2011, at 9:15 PM, Paul Colby wrote:
>
>> Hi,
>>
>> I'm running v4.7.0 installed with brew on my mac running 10.6. Before I do a
>> complete reinstall of my operating system I'd like to know if foreign works
>> for
>> anyone? I've made a c-file,
>>
>> -------------------------- test1.c -----------------------
>> #include <stdio.h>
>>
>> float testFloat(float f)
>> {
>> printf("Float: %f\n",f);
>> return 2.0*f;
>> }
>>
>> double testDouble(double d)
>> {
>> printf("Double: %lf\n",d);
>> return 2.0*d;
>> }
>> ------------------------------ end of file -----------------
>> These functions are compiled into a scheme
>> file using
>> csc stest2.scm test1.c
>> where the scheme file is,
>> ------------------------ stest2.scm ----------------------
>> (import foreign)
>> (define testFloat (foreign-lambda float testFloat float))
>> (define testDouble (foreign-lambda double testDouble double))
>> (print (testFloat 3.2))
>> (print (testDouble 3.2))
>> ----------------------- end of file ------------------------
>> running ./stest2 gives
>> ------------------------ output ---------------------------
>> Float: -0.000000
>> 17.0
>> Double: 3.200000
>> 17.0
>> ------------------------ end of output -------------------
>>
>> Am I missing something fundamental or is 3.2 == -0.0 and
>> 17==6.4?
>>
>> Thanks
>> Paul C.
>>
>>
>> _______________________________________________
>> Chicken-users mailing list
>> address@hidden
>> https://lists.nongnu.org/mailman/listinfo/chicken-users
>
>
> _______________________________________________
> Chicken-users mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/chicken-users