Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

cstdint

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.

like image 216
missingfaktor Avatar asked Dec 31 '09 20:12

missingfaktor


People also ask

Why is there no unsigned float in C?

Unsigned int is used to represent addresses and sizes, so computers natually need them. There isn't a need like this for floating point.

Is C++ float 32 or 64?

float is a 32-bit IEEE 754 single precision Floating Point Number – 1 bit for the sign, 8 bits for the exponent, and 23* for the value. float has 7 decimal digits of precision.

Is float always 32 bit?

The 'int pointer' size can be changed to 64 bits on 64 bits machines, since the memory address size is 64 bits. That means your 'argument' isn't valid. A float is then still a float too: usually we say it is 32 bits, but everyone is free to deviate from it.


2 Answers

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.

like image 65
Chris Lutz Avatar answered Oct 22 '22 06:10

Chris Lutz


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

like image 3
Adam Rosenfield Avatar answered Oct 22 '22 05:10

Adam Rosenfield