Hacker News new | past | comments | ask | show | jobs | submit login

> typedef float f32;

> typedef double f64;

Assuming float is 32 bits and double is 64 bits sounds like a foot-gun. OpenCV defines a float16_t [0], CUDA implements half-precision floats [1], micro-controllers implement whatever they want.

C++23 introduces fixed width floating-point types [2], but not aware of any way to enforce this in C. What I would suggest it to have a macro to check data is not lost at compile time.

Generally I agree with others, it might be better to leave some of these things as default for readability, even if it is not concise.

[0] https://docs.opencv.org/4.x/df/dc9/classcv_1_1float16__t.htm...

[1] https://docs.nvidia.com/cuda/cuda-math-api/group__CUDA__MATH...

[2] https://en.cppreference.com/w/cpp/types/floating-point




gcc has _Float<size> types

    typedef _Float32 f32;
    typedef _Float64 f64;
https://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html


It's not just gcc, they are in the C23 standard along with the _Decimal<size> types.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: