2005年04月13日 星期三 22:30
是硬件的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
Zeuux © 2025
京ICP备05028076号