summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2000-05-11 18:19:42 (GMT)
committerGuido van Rossum <guido@python.org>2000-05-11 18:19:42 (GMT)
commit71260b846e9ecafb21e52fd3f5b9ac74ebc8c1e6 (patch)
tree5022e60cabc3d790df52410d7d73cff56c058d23
parentdab6cb8f6dacc107e9482976ca2f8e0313f05131 (diff)
downloadcpython-71260b846e9ecafb21e52fd3f5b9ac74ebc8c1e6.zip
cpython-71260b846e9ecafb21e52fd3f5b9ac74ebc8c1e6.tar.gz
cpython-71260b846e9ecafb21e52fd3f5b9ac74ebc8c1e6.tar.bz2
Added math.rint() -- round according to current IEEE754 mode
-rw-r--r--Doc/lib/libmath.tex4
-rw-r--r--Include/mymath.h2
-rw-r--r--Lib/test/output/test_math1
-rw-r--r--Lib/test/test_math.py6
-rw-r--r--Modules/mathmodule.c3
5 files changed, 16 insertions, 0 deletions
diff --git a/Doc/lib/libmath.tex b/Doc/lib/libmath.tex
index af1ac10..f4fd2f2 100644
--- a/Doc/lib/libmath.tex
+++ b/Doc/lib/libmath.tex
@@ -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}
diff --git a/Include/mymath.h b/Include/mymath.h
index dd6ee58..3a8c62e 100644
--- a/Include/mymath.h
+++ b/Include/mymath.h
@@ -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
diff --git a/Lib/test/output/test_math b/Lib/test/output/test_math
index 2a98000..b0c48de 100644
--- a/Lib/test/output/test_math
+++ b/Lib/test/output/test_math
@@ -19,6 +19,7 @@ log
log10
modf
pow
+rint
sin
sinh
sqrt
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py
index 6d6bc44..aec4927 100644
--- a/Lib/test/test_math.py
+++ b/Lib/test/test_math.py
@@ -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)
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index d01de90..e76a32c 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -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},