Why don't we have <cstdfloat> in C++?
Asked Answered
A

3

10

Why doesn't C++ have <cstdfloat> header for floats like it has <cstdint> for integers?

EDIT :

By <cstdfloat> I mean header that provides typedefs for float and double. Much like qreal typedef in Qt. Hope my question is clear now.

Autocephalous answered 31/12, 2009 at 20:4 Comment(3)
<cstdint> is actually not part of Standard C++Scotney
What is it specifically from cstdint that you would like for floats?Prisoner
@Neil It will be added in C++0x thoughMarciamarciano
M
7

Often an application needs exactly 16 bits for an integer for, say, a bitfield, but having exactly 16 bits for a float is kind of useless. Manipulating bits in an integer is easy, so having exactly 16 is nice. Manipulating bits in a float requires casting it to an integer, making a float16 type rather extraneous.

By the same token, having an integral type capable of storing (and also performing math on) pointers is useful, but who ever needs to convert a pointer value to a floating point value, then perform floating point math on it, then convert it back to a pointer?

The point is that most of the functionality in stdint.h (or cstdint for C++, except that stdint.h is a C99 header and isn't technically part of C++) doesn't apply to floating point values.

Malang answered 31/12, 2009 at 20:20 Comment(0)
U
3

Are you perhaps looking for <float.h> and its C++ brother <cfloat> instead?

Upstate answered 31/12, 2009 at 20:7 Comment(3)
<float.h> is a different thing. I am talking about header that provides typedefs for float and double. Much like qreal typedef in Qt. Hope you understand my question now.Autocephalous
Then you should specify that in your question. Your question is incredibly vague.Upstate
@Rosenfield : Sorry. Edited my question now.Autocephalous
O
1

<stdfloat> has been proposed and is a part of C++23.

<stdfloat.h> and <cstdfloat> were once proposed to WG14 more than a decade ago. This seemed to be revived years later (notably, ISO/IEC TS 18661-3:2015), but these types were still pushed by C++ side with some different styles (in some time WG14 did not even remember why the types are extended; and actually they should be extended because they should not break current implementations where float, double or long double are not types conforming to IEC 60559). Nevertheless, there were still some well-known divergence even though both C and C++ adopted some of these types (std::bfloat16_t is not in C and decimal floating types are not specified in C++). In particular, the meaning of extended floating-point types are similar to those of extended integer types, while C's extended floating types directly follows IEC 60559 (e.g. _Float64x). ISO C23 provides interchange floating types in Annex H with these types built-in, and there is simply no standard header mapped them to C++ ones. (Hopefully, the native type names can be also supported by the implementations of C++ as extensions.)

Objective answered 7/4 at 13:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.