<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content=
"HTML Tidy for OS/2 (vers 1 September 2005), see www.w3.org">
<style type="text/css">
del { font-weight:bold;background-color:#ffa0a0 }
ins { font-weight:bold;background-color:#a0ffa0 }
blockquote {
display: block;
font-family: "Times New Roman";
background-color:lightgray;
margin-top: 1em;
margin-bottom: 1em;
margin-left: 40px;
margin-right: 40px
}
</style>
<title>N2xxx: intmax_t and math functions</title>
</head>
<body>
<p><br>
<!-- Who are the authors... -->
<b>Submitter:</b>Fred J. Tydeman<br>
<!-- What is the date of submission. yyyy-mm-dd -->
<b>Submission Date:</b> 2020-mm-dd<br>
<b>Document:</b> WG14 N2xxx<br>
<b>Title:</b> N2xxx: intmax_t and math functions<br>
<b>Reference Documents:</b> N2478</p>
<p>Summary</p>Due to issues raised by the WG14 committee with
[u]intmax_t, several of the CFP related functions ([u]fromfp[x],
compoundn, pown, rootn) should be changed to not use [u]intmax_t.
In general, replace [u]intmax_t with the floating type used as
the parameter.
<p>Change</p>
<blockquote>
7.12.9.10 The fromfp and ufromfp functions
</blockquote>
<blockquote>
Synopsis
</blockquote>
<blockquote>
<pre>
<code>
1 #include <stdint.h>
#include <math.h>
intmax_t fromfp(double x, int round, unsigned int width);
intmax_t fromfpf(float x, int round, unsigned int width);
intmax_t fromfpl(long double x, int round, unsigned int width);
uintmax_t ufromfp(double x, int round, unsigned int width);
uintmax_t ufromfpf(float x, int round, unsigned int width);
uintmax_t ufromfpl(long double x, int round, unsigned int width);
#ifdef __STDC_IEC_60559_DFP__
intmax_t fromfpd32(_Decimal32 x, int round, unsigned int width);
intmax_t fromfpd64(_Decimal64 x, int round, unsigned int width);
intmax_t fromfpd128(_Decimal128 x, int round, unsigned int width);
uintmax_t ufromfpd32(_Decimal32 x, int round, unsigned int width);
uintmax_t ufromfpd64(_Decimal64 x, int round, unsigned int width);
uintmax_t ufromfpd128(_Decimal128 x, int round, unsigned int width);
#endif
</code>
</pre>
</blockquote>
<blockquote>
Description
</blockquote>
<blockquote>
<p>2 The <b>fromfp</b> and <b>ufromfp</b> functions round x,
using the math rounding direction indicated by <b>round</b>, to
a signed or unsigned integer, respectively, of <b>width</b>
bits, and return the result value in the integer type
designated by <b>intmax_t</b> or <b>uintmax_t</b>,
respectively. If the value of the <b>round</b> argument is not
equal to the value of a math rounding direction macro, the
direction of rounding is unspecified. If the value of
<b>width</b> exceeds the width of the function type, the
rounding is to the full width of the function type. The
<b>fromfp</b> and <b>ufromfp</b> functions do not raise the
"inexact" floating-point exception. If x is infinite or NaN or
rounds to an integral value that is outside the range of any
supported integer type of the specified width, or if width is
zero, the functions return an unspecified value and a domain
error occurs.</p>
</blockquote>
<blockquote>
3 Returns
</blockquote>
<blockquote>
<p>The <b>fromfp</b> and <b>ufromfp</b> functions return the
rounded integer value.</p>
</blockquote>
<blockquote>
<p>4 EXAMPLE Upward rounding of double x to type int, without
raising the "inexact" floating-point exception, is achieved
by</p>
<pre>
<code>
(int)fromfp(x, FP_INT_UPWARD, INT_WIDTH)
</code>
</pre>
</blockquote>
<p>to</p>
<blockquote>
7.12.9.10 The fromfp and ufromfp functions
</blockquote>
<blockquote>
Synopsis
</blockquote>
<blockquote>
<pre>
<code>
1 #include <stdint.h>
#include <math.h>
<del>intmax_t</del> <ins>double</ins> fromfp(double x, int round, unsigned int width);
<del>intmax_t</del> <ins>float</ins> fromfpf(float x, int round, unsigned int width);
<del>intmax_t</del> <ins>long double</ins> fromfpl(long double x, int round, unsigned int width);
<del>uintmax_t</del> <ins>double</ins> ufromfp(double x, int round, unsigned int width);
<del>uintmax_t</del> <ins>float</ins> ufromfpf(float x, int round, unsigned int width);
<del>uintmax_t</del> <ins>long double</ins> ufromfpl(long double x, int round, unsigned int width);
#ifdef __STDC_IEC_60559_DFP__
<del>intmax_t</del> <ins>_Decimal32</ins> fromfpd32(_Decimal32 x, int round, unsigned int width);
<del>intmax_t</del> <ins>_Decimal64</ins> fromfpd64(_Decimal64 x, int round, unsigned int width);
<del>intmax_t</del> <ins>_Decimal128</ins> fromfpd128(_Decimal128 x, int round, unsigned int width);
<del>uintmax_t</del> <ins>_Decimal32</ins> ufromfpd32(_Decimal32 x, int round, unsigned int width);
<del>uintmax_t</del> <ins>_Decimal64</ins> ufromfpd64(_Decimal64 x, int round, unsigned int width);
<del>uintmax_t</del> <ins>_Decimal128</ins> ufromfpd128(_Decimal128 x, int round, unsigned int width);
#endif
</code>
</pre>
</blockquote>
<blockquote>
Description
</blockquote>
<blockquote>
<p>2 The <b>fromfp</b> and <b>ufromfp</b> functions round x,
using the math rounding direction indicated by <b>round</b>, to
a signed or unsigned integer, respectively, of <b>width</b>
bits, and return the result value <del>in the integer type
designated by <b>intmax_t</b> or <b>uintmax_t</b>,
respectively</del><ins>as in integer in floating-point
format</ins>. If the value of the <b>round</b> argument is not
equal to the value of a math rounding direction macro, the
direction of rounding is unspecified. If the value of
<b>width</b> exceeds the width of the function type, the
rounding is to the full width of the function type. The
<b>fromfp</b> and <b>ufromfp</b> functions do not raise the
"inexact" floating-point exception. If x is infinite or NaN or
rounds to an integral value that is outside the range of any
supported integer type of the specified width, or if width is
zero, the functions return <del>an unspecified
value</del><ins>a NaN (if available, else HUGE_VAL)</ins> and a
domain error occurs.</p>
</blockquote>
<blockquote>
3 Returns
</blockquote>
<blockquote>
<p>The <b>fromfp</b> and <b>ufromfp</b> functions return the
rounded integer value.</p>
</blockquote>
<blockquote>
<p>4 EXAMPLE Upward rounding of double x to type int, without
raising the "inexact" floating-point exception<ins>; unsigned
wrapping is not performed in the second call</ins>, is achieved
by</p>
<pre>
<code>
(int)fromfp(x, FP_INT_UPWARD, INT_WIDTH)
<ins>fromfp(-3.0, FP_INT_UPWARD, UINT_WIDTH) /* domain error */</ins>
</code>
</pre>
</blockquote>
</body>
</html>