[linux-l] C kurze Version

Ivan F. Villanueva B. iv at artificialidea.com
Di Sep 12 14:34:53 CEST 2006


Am Mo, Sep 11, 2006 06:55:57 +0000, Rocco Rutte schrieb:
> #include <math.h>
> #include <stdio.h>
> 
> #define EPS     0.00001
> #define CNT     64
> #define STEP    0.1
> #define DIFF(Y,X)       (Y(X+EPS)-Y(X))/EPS
> 
> static double x2(double x) { return x*x; }
> static double x3(double x) { return x*x*x; }
> 
> int main(int argc, char** argv) {
>   struct {
>     double (*func)(double);
>     const char* name;
>   } Funcs[] = { { x2,"x^2" }, { x3,"x^3" }, { sin,"sin" }, 
>                 { cos,"cos" }, { 0,0 } };
>   unsigned short i,j;
>   double x;
> 
>   for (i=0; Funcs[i].name; i++)
>     for (j=0; j<CNT; j++, x=j*STEP)
>       printf("%s(%f)' = %f\n",Funcs[i].name,x,DIFF(Funcs[i].func,x));
> }

Sehr schön. Danke.

P.S. Ich habe alle Versionen in
http://www.artificialidea.com/author/wiki/doku.php?id=languages_comparison
kopiert. Autoren können Ihre Name hinzufügen wenn sie wollen. Es ist eine Wiki.

Die Seite (nach einer Update von Dokuwiki) funktioniert wieder gut.

Ein C++, Ruby, Bash, und Perl hätte ich gerne noch in der Sammlung.

-- 
Ivan F. Villanueva B.
A.I. library:   http://www.artificialidea.com
<<<          The European Patent Litigation Agreement (EPLA)          >>>
<<<            will bring Software patents by the backdoor            >>>
<<<  http://www.no-lobbyists-as-such.com/florian-mueller-blog/epla/   >>>
<<<                     http://wiki.ffii.de/EplaEn                    >>>



Mehr Informationen über die Mailingliste linux-l