[cfp-interest 3631] Re: strtodN
Jim Thomas
jaswthomas at sbcglobal.net
Wed Sep 24 14:13:28 PDT 2025
> On Sep 17, 2025, at 8:33 PM, Fred J. Tydeman <tydeman at tybor.com> wrote:
>
> C23: (N3219)
>
> 5.2.5.3.4 Characteristics of decimal floating types in <float.h>
>
> 2 DEC_EVAL_METHOD is the decimal floating-point analog of
> FLT_EVAL_METHOD (5.2.5.3.3). Its implementation-defined value
> characterizes the use of evaluation formats for decimal floating
> types: ... operations and constants ...
>
> 7.24.1.6 The strtodN functions
>
> 5 If the subject sequence has the expected form for a decimal
> floating-point number, the value resulting from the conversion is
> correctly rounded and the coefficient c and the quantum exponent q are
> determined by the rules in 6.4.4.3 for a decimal floating constant of
> decimal type.
>
> My question is about "correctly rounded".
>
> "correctly rounded" to what precision and range?
>
> Do the strtodN functions first round as per DEC_EVAL_METHOD and then
> to the return type of the function (possible double rounding)?
FLT_EVAL_METHOD and DEC_EVAL_METHOD only apply as specified in 5.3.5.3.3 #26, which doesn’t include library functions.
>
> Or, do they just round to the return type of the function?
To the return type of the function.
>
> If it is as per DEC_EVAL_METHOD, what do they do if it is -1?
DEC_EVAL_METHOD doesn’t apply.
>
> Do the "operations" covered by DEC_EVAL_METHOD include functions?
5.3.5.3.3.#26 says “The value of FLT_EVAL_METHOD does not characterize values returned by function calls.” (DEC_EVAL_METHOD is the decimal analog of FLT_EVAL_METHOD.)
>
> Are the strtodN functions allowed to return a value with greater range
> or precision than the return type?
>
> Footnote 190 says yes:
It's Footnote 197 in N3550.
> 190) The return statement is not an assignment. The overlap
> restriction of 6.5.17.2 does not apply to the case of function
> return. The representation of floating-point values can have wider
> range or precision than implied by the type; a cast can be used to
> remove this extra range and precision.
>
> F.6 The return statement says no:
> If the return expression is evaluated in a floating-point format
> different from the return type, the expression is converted as if by
> assignment430) to the return type of the function and the resulting
> value is returned to the caller.
>
> 430) Assignment removes any extra range and precision.
Footnote 197 is in the main body of the standard. Decimal floating point conforms to Annex F (and F.6) which is more restrictive than the main body of the standard. F.6 does not contradict Footnote 197.
- Jim Thomas
>
> H.5.2 Constants
> 6 The quantum exponent of a floating constant of decimal floating type
> is the same as for the result value of the corresponding strtodN or
> strtodNx function (H.12.3) for the same numeric string.
>
>
> ---
> Fred J. Tydeman Tydeman Consulting
> tydeman at tybor.com Testing, numerics, programming
> +1 (702) 608-6093 Vice-chair of INCITS/C (ANSI "C")
> Sample C17+FPCE tests: http://www.tybor.com
> Savers sleep well, investors eat well, spenders work forever.
>
> _______________________________________________
> cfp-interest mailing list
> cfp-interest at oakapple.net
> http://mailman.oakapple.net/mailman/listinfo/cfp-interest
More information about the cfp-interest
mailing list