Python论坛  - 讨论区

标题:Re: [python-chinese] Re: [金山毒霸识别此邮件为垃 圾邮件]round 的问题

2005年04月13日 星期三 22:30

Gerald Lee leejd80 at gmail.com
Wed Apr 13 22:30:41 HKT 2005

是硬件的BUG吧:)

05-4-13,albertlee <hanzhupeng at 163.com> 写道:
> 
> 俄,找到原因了,是浮点数的表示
> 
> 1.255 在内存中是 1.2549999999999999
> 
> 不知道这个问题,算不算是个bug
> 
> ======= 2005-04-13 22:09:35 您在来信中写道:=======
> 
> >>>> round(1.25,1)
> >1.3
> >>>> round(1.255,2)
> >1.25
> >~~~~~~~~~~~ 为什么不是期望中的 1.26 ?
> >
> >我找了源代码中的实现:
> >
> >static PyObject *
> >builtin_round(PyObject *self, PyObject *args)
> >{
> > double x;
> > double f;
> > int ndigits = 0;
> > int i;
> >
> > if (!PyArg_ParseTuple(args, "d|i:round", &x;, &ndigits;))
> > return NULL;
> > f = 1.0;
> > i = abs(ndigits);
> > while (--i >= 0)
> > f = f*10.0;
> > if (ndigits < 0)
> > x /= f;
> > else
> > x *= f;
> > if (x >= 0.0)
> > x = floor(x + 0.5);
> > else
> > x = ceil(x - 0.5);
> > if (ndigits < 0)
> > x *= f;
> > else
> > x /= f;
> > return PyFloat_FromDouble(x);
> >}
> >
> >感觉没有问题阿?
> >
> >
> >
> >
> >致
> >礼!
> >
> >
> >albertlee
> >hanzhupeng at 163.com
> >2005-04-13
> >_______________________________________________
> >python-chinese list
> >python-chinese at lists.python.cn
> >http://python.cn/mailman/listinfo/python-chinese
> >
> 
> = = = = = = = = = = = = = = = = = = = =
> 
> 
>> 礼!
> 
> albertlee
> hanzhupeng at 163.com
> 2005-04-13
> 
> 
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
> 
> 
> 


-- 
My Blog >> http://leejd.cndev.org
My QQ >> 9847243
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050413/ff9ac98d/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号