[Cfp-interest 1682] Re: intmax_t removal

Jim Thomas jaswthomas at sbcglobal.net
Fri Jun 26 14:39:18 PDT 2020


Converging. Please see comments below.

- Jim Thomas

> On Jun 26, 2020, at 1:17 PM, Fred J. Tydeman <tydeman at tybor.com> wrote:
> 
> On Thu, 25 Jun 2020 17:02:29 -0700 Jim Thomas wrote:
>> 
>> Here's a cut at a Description for fromfp and ufromfp functions with floating return types
> 
> I took your words as a starting point.  Attached is my latest version.
> In my web browser, the text being removed is red and the text being added is green.
> 
> 
> 
> ---
> Fred J. Tydeman        Tydeman Consulting
> tydeman at tybor.com <mailto:tydeman at tybor.com>      Testing, numerics, programming
> +1 (702) 608-6093      Vice-chair of PL22.11 (ANSI "C")
> Sample C99+FPCE tests: http://www.tybor.com <http://www.tybor.com/>
> Savers sleep well, investors eat well, spenders work forever.
> 
> 
> Submitter:Fred J. Tydeman
> Submission Date: 2020-mm-dd
> Document: WG14 N2xxx
> Title: N2xxx: intmax_t and math functions
> Reference Documents: N2478, N2525
> 
> Summary
> 
> 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.
> The WG14 consideration of removing [u]intmax_t, sparked the CFP discussion. We concluded that changing the interfaces to not use [u]intmax_t would be better anyway (even if [u]intmax_t were not removed). Introducing type [u]intmax_t into an expression via a function return type could have unpredictable negative performance implications.
> 
> In general, replace [u]intmax_t with the floating type used as the parameter.
> 
> Change
> 
> 7.12.9.10 The fromfp and ufromfp functions
> Synopsis
> 
> 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
> 
>     
> Description
> 2 The fromfp and ufromfp functions round x, using the math rounding direction indicated by round, to a signed or unsigned integer, respectively, of width bits, and return the result value in the integer type designated by intmax_t or uintmax_t, respectively. If the value of the round argument is not equal to the value of a math rounding direction macro, the direction of rounding is unspecified. If the value of width exceeds the width of the function type, the rounding is to the full width of the function type. The fromfp and ufromfp 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.
> 
> 3 Returns
> The fromfp and ufromfp functions return the rounded integer value.
> 
> 4 EXAMPLE Upward rounding of double x to type int, without raising the "inexact" floating-point exception, is achieved by
> 
> 
> (int)fromfp(x, FP_INT_UPWARD, INT_WIDTH)
> 
>     
> to
> 
> 7.12.9.10 The fromfp and ufromfp functions
> Synopsis
> 
> 1 #include <stdint.h>
>   #include <math.h>
>   intmax_t double fromfp(double x, int round, unsigned int width);
>   intmax_t float fromfpf(float x, int round, unsigned int width);
>   intmax_t long double fromfpl(long double x, int round, unsigned int width);
>   uintmax_t double ufromfp(double x, int round, unsigned int width);
>   uintmax_t float ufromfpf(float x, int round, unsigned int width);
>   uintmax_t long double ufromfpl(long double x, int round, unsigned int width);
>   #ifdef __STDC_IEC_60559_DFP__
>   intmax_t _Decimal32 fromfpd32(_Decimal32 x, int round, unsigned int width);
>   intmax_t _Decimal64 fromfpd64(_Decimal64 x, int round, unsigned int width);
>   intmax_t _Decimal128 fromfpd128(_Decimal128 x, int round, unsigned int width);
>   uintmax_t _Decimal32 ufromfpd32(_Decimal32 x, int round, unsigned int width);
>   uintmax_t _Decimal64 ufromfpd64(_Decimal64 x, int round, unsigned int width);
>   uintmax_t _Decimal128 ufromfpd128(_Decimal128 x, int round, unsigned int width);
>   #endif
> 
>     
> Description
> 2 The fromfp and ufromfp functions round x, using the math rounding direction indicated by round, to a signed or unsigned integer, respectively. , of width bits, and return the result value in the integer type designated by intmax_t or uintmax_t, respectively. If width is nonzero and the resulting integer is within the range
> 
>    [-2**(width-1), 2**(width-1) - 1], for signed
>    [0, 2**width - 1], for unsigned
> 
> the functions return the integer value (represented in floating type). Otherwise, if width is zero or x does not round to an integer within the range, the functions return a NaN (if available), else an infinity (if available), else a HUGE_VAL, of the type of the xargument, and a domain error occurs. If the value of the round argument is not equal to the value of a math rounding direction macro (7.12), the direction of rounding is unspecified. If the value of width exceeds the width of the function type, the rounding is to the full width of the function type. The fromfp and ufromfp 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.
> 
The sentence "If the value of width exceeds the width of the function type, the rounding is to the full width of the function type.” doesn’t add anything. It can be removed.

Consider changing "else an infinity (if available), else a HUGE_VAL, of the type of the xargument” to “else the value of x”.
> 3 Returns
> The fromfp and ufromfp functions return the rounded integer value.
> 
> 4 EXAMPLE Upward rounding of double x to type int, without raising the "inexact" floating-point exception; unsigned wrapping is not performed in the second call, is achieved by
> 
> 
> (int)fromfp(x, FP_INT_UPWARD, INT_WIDTH)
> ufromfp(-3.0, FP_INT_UPWARD, UINT_WIDTH) /* domain error */
> 
>     
If we want the example about unsigned wrapping, it should be a separate example. Maybe change “unsigned wrapping” to “unsigned integer wrapping”.
> Also, in F.10.6.10:
> 
> Change:
> 
> 1 The fromfp and ufromfp functions raise the "invalid" floating-point exception and return an unspecified value if the floating-point argument 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.
> 
> to:
> 
> 1 The fromfp and ufromfp functions raise the "invalid" floating-point exception and return an unspecified value a NaN if the argument width is zero or if the floating-point argument x is infinite or NaN or rounds to an integer value that is outside the range of any supported integer type of the specified width determined by the argument width (see 7.12.9.2).
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.oakapple.net/pipermail/cfp-interest/attachments/20200626/6d1ae10d/attachment-0001.htm>


More information about the Cfp-interest mailing list