]> granicus.if.org Git - python/commitdiff
Added math.rint() -- round according to current IEEE754 mode
authorGuido van Rossum <guido@python.org>
Thu, 11 May 2000 18:19:42 +0000 (18:19 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 11 May 2000 18:19:42 +0000 (18:19 +0000)
Doc/lib/libmath.tex
Include/mymath.h
Lib/test/output/test_math
Lib/test/test_math.py
Modules/mathmodule.c

index af1ac102b414fb7bb8a3172196a9e587f7e3baad..f4fd2f2d9503511b7c880f774547de5a55d36aed 100644 (file)
@@ -93,6 +93,10 @@ carry the sign of \var{x}.  The integer part is returned as a real.
 Return \code{\var{x}**\var{y}}.
 \end{funcdesc}
 
+\begin{funcdesc}{rint}{x, y}
+Return the integer nearest to \var{x} as a real.
+\end{funcdesc}
+
 \begin{funcdesc}{sin}{x}
 Return the sine of \var{x}.
 \end{funcdesc}
index dd6ee58841d8629ec6230d0271f0b96d14ea3644..3a8c62e010f34f9c2f22035fb15a6e61911dcb14 100644 (file)
@@ -48,6 +48,7 @@ extern double hypot Py_PROTO((double, double));
 #undef log
 #undef log10
 #undef pow
+#undef rint
 #undef sin
 #undef sinh
 #undef sqrt
@@ -67,6 +68,7 @@ extern double hypot Py_PROTO((double, double));
 #define log logd
 #define log10 log10d
 #define pow powd
+#define rint rintd
 #define sin sind
 #define sinh sinhd
 #define sqrt sqrtd
index 2a980003a5cc9fca66dc3f633a2020bfc18dcbdb..b0c48defd4bc61fc27fbd8485af5a64b01f82bb3 100644 (file)
@@ -19,6 +19,7 @@ log
 log10
 modf
 pow
+rint
 sin
 sinh
 sqrt
index 6d6bc44953833e8bc2d5745db8b3d757611a0014..aec49273a5476810972ab0f39cd0d8d7bcdc4d25 100644 (file)
@@ -129,6 +129,12 @@ testit('pow(1,0)', math.pow(1,0), 1)
 testit('pow(2,1)', math.pow(2,1), 2)
 testit('pow(2,-1)', math.pow(2,-1), 0.5)
 
+print 'rint'
+testit('rint(0.7)', math.rint(0.7), 1)
+testit('rint(-0.3)', math.rint(-0.3), 0)
+testit('rint(2.5)', math.rint(2.5), 2)
+testit('rint(3.5)', math.rint(3.5), 4) 
+
 print 'sin'
 testit('sin(0)', math.sin(0), 0)
 testit('sin(pi/2)', math.sin(math.pi/2), 1)
index d01de9056919c16a2d0dd637c7a2e53c7ab226af..e76a32c9e82e69b0e647133fd7e6a77a9bfe2430 100644 (file)
@@ -156,6 +156,8 @@ FUNC2(math_pow, power, math_pow_doc,
 FUNC2(math_pow, pow, math_pow_doc,
       "pow(x,y)\n\nReturn x**y.")
 #endif
+FUNC1(math_rint, rint, math_rint_doc,
+      "rint(x)\n\nReturn the integer nearest to x as a real.")
 FUNC1(math_sin, sin, math_sin_doc,
       "sin(x)\n\nReturn the sine of x.")
 FUNC1(math_sinh, sinh, math_sinh_doc,
@@ -267,6 +269,7 @@ static PyMethodDef math_methods[] = {
        {"log10",       math_log10,     0,      math_log10_doc},
        {"modf",        math_modf,      0,      math_modf_doc},
        {"pow",         math_pow,       0,      math_pow_doc},
+       {"rint",        math_rint,      0,      math_rint_doc},
        {"sin",         math_sin,       0,      math_sin_doc},
        {"sinh",        math_sinh,      0,      math_sinh_doc},
        {"sqrt",        math_sqrt,      0,      math_sqrt_doc},