[cfp-interest 3602] strtodN

Fred J. Tydeman tydeman at tybor.com
Wed Sep 17 20:33:24 PDT 2025


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)?

Or, do they just round to the return type of the function?

If it is as per DEC_EVAL_METHOD, what do they do if it is -1?

Do the "operations" covered by DEC_EVAL_METHOD include functions?

Are the strtodN functions allowed to return a value with greater range
or precision than the return type?  

Footnote 190 says yes:
  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.

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.



More information about the cfp-interest mailing list