summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2017-07-26 10:07:35 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2017-07-26 10:07:35 +0000
commit57b62415be74782fbcd391cc3e9dd02a4b58cd0e (patch)
tree8bf6f83ab6e156519b61b2f0eb87ea1f70d1a10a /doc
parent79f4bdd5caa21c72ec6deb51c2caec68974d8d8d (diff)
downloadmpfr-57b62415be74782fbcd391cc3e9dd02a4b58cd0e.tar.gz
[mpfr.texi] added example showing how to emulate fixed-point arithmetic
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@11595 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'doc')
-rw-r--r--doc/mpfr.texi22
1 files changed, 21 insertions, 1 deletions
diff --git a/doc/mpfr.texi b/doc/mpfr.texi
index 52c520041..8764d46f4 100644
--- a/doc/mpfr.texi
+++ b/doc/mpfr.texi
@@ -3372,10 +3372,30 @@ This is an example of how to emulate binary double IEEE 754 arithmetic
Note that @code{mpfr_set_emin} and @code{mpfr_set_emax} are called early
enough in order to make sure that all computed values are in the current
exponent range.
-
Warning! This emulates a double IEEE 754 arithmetic with correct rounding
in the subnormal range, which may not be the case for your hardware.
+Below is another example showing how to emulate fixed-point arithmetic.
+Here we compute the sine of the integers 1 to 17 with a fixed-point
+arithmetic rounded at @m{2^{-42}, 2 power -42}:
+
+@example
+@{
+ mpfr_t x; int i, inex;
+
+ mpfr_set_emin (-41);
+ mpfr_init2 (x, 42);
+ for (i = 1; i <= 17; i++)
+ @{
+ mpfr_set_ui (x, i, MPFR_RNDN);
+ inex = mpfr_sin (x, x, MPFR_RNDZ);
+ mpfr_subnormalize (x, inex, MPFR_RNDZ);
+ mpfr_dump (x);
+ @}
+ mpfr_clear (x);
+@}
+@end example
+
@deftypefun void mpfr_clear_underflow (void)
@deftypefunx void mpfr_clear_overflow (void)
@deftypefunx void mpfr_clear_divby0 (void)