Programmiersprachen (Re: [linux-l] Ruby: sehr cool, aber laaaahm... wie geht's schneller?! - D?)

Ivan F. Villanueva B. iv at artificialidea.com
So Aug 27 12:43:21 CEST 2006


Am Do, Aug 24, 2006 09:40:44 +0200, Axel Weiß schrieb:
> Oliver Bandel wrote:
> > Vorschläge in anderen Sprachen?
> > (Perl, Java, C, ...?!)
> 
> Hier, 15 Minuten:
> --------------------------------
> [C code]

Hier Java, 15 Minuten auch:
--------------------------

public class Derivative {
    private static final double CALCULATIONS = 64 ;
    private static final double STEP = 0.1 ;
    static double EPS = 0.001 ;
    static interface Function {
        String getName() ;
        double value(double x) ;
    }
    static Function[] functions = new Function[] {
        new Function() {
            public String getName() { return "sin" ;}
            public double value(double x) { return Math.sin(x) ; }
        },
        new Function() {
            public String getName() { return "cos" ;}
            public double value(double x) { return Math.cos(x) ; }
        }} ;
    static double derive(Function f, double x) {
        return f.value(x + EPS / 2) - f.value(x - EPS /2) ;
    }
    public static void main(String[] args) {
        for (Function f : functions) {
            System.out.println("Calculation of " + f.getName()) ;
            for (int i = 0 ; i < CALCULATIONS ; i++) {
                double x = STEP * i ;
                double y = f.value(x) ;
                double dy = derive(f, x) ;
                System.out.printf("x: %f, y: %f, y': %f\n", x, y, dy) ;
            }
        }
    }
}

Ich würde es gerne in Perl, Rubby, Python, Ocalm und D sehen.

Gruß,
-- 
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