[pyar] Int anti-intuitivo

Roberto Alsina ralsina en netmanagers.com.ar
Mie Nov 17 08:24:06 ART 2010


On Tuesday 16 November 2010 21:22:30 QliX=D! [aka EHB] wrote:
> No, no tiene por que ser relativo en este caso por que:
> 
> In [1]: int(float(9999999999999999.0))
> Out[1]: 9999999999999998L
> 
> In [2]: int(float("9999999999999999.0"))
>  Out[2]: 9999999999999998L
> 
> In [3]:
> 
> In [4]: float("9999999999999999.0")
> Out[4]: 9999999999999998.0
> 
> In [5]: float("9999999999999999.0")
> Out[5]: 9999999999999998.0
> 
> Se comporta de la misma HORRIBLE forma. Por la HORRIBLE presicion de
> Python. (Si use horrible como calificativo de python... y que? :P)

No, es porque son floats y los floats son así. Fijate lo que tu ejemplo hace 
en C:

[ralsina en hp ~]$ cat f.c
int main() {
    double x1;
    x1 = strtold("9999999999999999.0");
    printf ("%f\n", x1);
}
[ralsina en hp ~]$ tcc -run f.c
-1910781505.000000



More information about the pyar mailing list