• [^] # Re: Oui mais...

    Posté par . En réponse au journal Cohérence des fonctions d'arrondi. Évalué à 1.

    Les langages de type C/C++/Java (implicitement, Scala/Clojure aussi du coup) utilisent l'arrondi mathématique classique. Par exemple:

    /* rnd.c -- build with LDFLAGS=-lm make rnd */
    #include <stdio.h>
    #include <math.h>
    int main(void) {
     printf("round(%.1f) = %d (%.1f)\n", 0.5, (int)round(0.5), round(0.5));
     return 0;
    }

    ... imprimera round(0.5) = 1 (1.0).

    En Scala:

    (math round 0.5)

    ... imprimera res0: Long = 1 dans l'interpréteur.