[Patches] introducing math.rint

Peter Schneider-Kamp peter@schneider-kamp.de
Thu, 11 May 2000 18:44:47 +0200


This is a multi-part message in MIME format.
--------------3E43382254608E73673E4C24
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Problem:
"4.26. math.rint is missing" from to-do list:
Although the math modules provides a wrapper around
ceil(3) and floor(3), there is no wrapper around rint(3).
This is necessary for IEEE-conforming rounding.
Edit this entry / Log info / Last changed on Tue Oct 26 12:49:36 1999 by
Martin v. Loewis

Solution:
introduced math.rint to Modules/mathmodule.c
updated documentation / updated Include/mymath.h / updated tests
patch attached as plaintext context diff
--
I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under
copyright, patent or other rights or interests ("claims").  To
the extent that I have any such claims, I hereby grant to CNRI a
nonexclusive, irrevocable, royalty-free, worldwide license to
reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part
of the Python software and its related documentation, or any
derivative versions thereof, at no cost to CNRI or its licensed
users, and to authorize others to do so.

I acknowledge that CNRI may, at its sole discretion, decide
whether or not to incorporate this contribution in the Python
software and its related documentation.  I further grant CNRI
permission to use my name and other identifying information
provided to CNRI by me for use in connection with the Python
software and its related documentation.
--
Peter Schneider-Kamp          ++47-7388-7331
Herman Krags veg 51-11        mailto:peter@schneider-kamp.de
N-7050 Trondheim              http://schneider-kamp.de
--------------3E43382254608E73673E4C24
Content-Type: text/plain; charset=us-ascii;
 name="math.rint.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="math.rint.patch"

diff -c --recursive python/dist/src/Doc/lib/libmath.tex python-mod/dist/src/Doc/lib/libmath.tex
*** python/dist/src/Doc/lib/libmath.tex	Mon Apr  3 22:13:53 2000
--- python-mod/dist/src/Doc/lib/libmath.tex	Thu May 11 18:04:14 2000
***************
*** 93,98 ****
--- 93,102 ----
  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 -c --recursive python/dist/src/Include/mymath.h python-mod/dist/src/Include/mymath.h
*** python/dist/src/Include/mymath.h	Mon Nov  2 17:21:39 1998
--- python-mod/dist/src/Include/mymath.h	Thu May 11 18:02:46 2000
***************
*** 48,53 ****
--- 48,54 ----
  #undef log
  #undef log10
  #undef pow
+ #undef rint
  #undef sin
  #undef sinh
  #undef sqrt
***************
*** 67,72 ****
--- 68,74 ----
  #define log logd
  #define log10 log10d
  #define pow powd
+ #define rint rintd
  #define sin sind
  #define sinh sinhd
  #define sqrt sqrtd
diff -c --recursive python/dist/src/Lib/test/output/test_math python-mod/dist/src/Lib/test/output/test_math
*** python/dist/src/Lib/test/output/test_math	Wed Dec 11 00:19:51 1996
--- python-mod/dist/src/Lib/test/output/test_math	Thu May 11 18:01:16 2000
***************
*** 19,24 ****
--- 19,25 ----
  log10
  modf
  pow
+ rint
  sin
  sinh
  sqrt
diff -c --recursive python/dist/src/Lib/test/test_math.py python-mod/dist/src/Lib/test/test_math.py
*** python/dist/src/Lib/test/test_math.py	Thu Aug 29 21:00:46 1996
--- python-mod/dist/src/Lib/test/test_math.py	Thu May 11 18:01:02 2000
***************
*** 129,134 ****
--- 129,140 ----
  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 -c --recursive python/dist/src/Modules/mathmodule.c python-mod/dist/src/Modules/mathmodule.c
*** python/dist/src/Modules/mathmodule.c	Mon May  8 16:29:38 2000
--- python-mod/dist/src/Modules/mathmodule.c	Thu May 11 17:58:45 2000
***************
*** 156,161 ****
--- 156,163 ----
  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,
***************
*** 266,272 ****
  	{"log",		math_log,	0,	math_log_doc},
  	{"log10",	math_log10,	0,	math_log10_doc},
  	{"modf",	math_modf,	0,	math_modf_doc},
! 	{"pow",		math_pow,	0,	math_pow_doc},
  	{"sin",		math_sin,	0,	math_sin_doc},
  	{"sinh",	math_sinh,	0,	math_sinh_doc},
  	{"sqrt",	math_sqrt,	0,	math_sqrt_doc},
--- 268,275 ----
  	{"log",		math_log,	0,	math_log_doc},
  	{"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},

--------------3E43382254608E73673E4C24--