←back to thread

73 points seg_fault | 1 comments | | HN request time: 0.205s | source

Since there is so much interest on HN in floats lately and their software implementations, I wanted to show mine. It has no use and is just for teaching me floats and C++. Give me your thoughts.
Show context
listeria ◴[] No.41908198[source]
Consider dropping the specializations for the type traits, given that it's undefined behavior:

https://en.cppreference.com/w/cpp/types/is_fundamental

https://en.cppreference.com/w/cpp/types/is_floating_point

https://en.cppreference.com/w/cpp/types/is_arithmetic

https://en.cppreference.com/w/cpp/types/is_scalar

https://en.cppreference.com/w/cpp/types/is_object

replies(2): >>41908384 #>>41909333 #
seg_fault ◴[] No.41908384[source]
I don't get what you mean. I thought they specify how the type can be used?
replies(2): >>41908617 #>>41908663 #
secondcoming ◴[] No.41908617[source]
Technically, you're not supposed to add your own specialisations to the `std` namespace
replies(1): >>41908849 #
pmalynin ◴[] No.41908849[source]
In general this isn’t true (i guess it is in this specific context). For example I believe it’s totally expected to specialize std hash
replies(1): >>41909632 #
tyleo ◴[] No.41909632[source]
I’ve also done this with hash… though given the footguns scattered about, I wouldn’t be surprised if it broke the spec.
replies(1): >>41911240 #
1. Conscat ◴[] No.41911240[source]
That is a completely intended way to use std::hash, along with a few other functions like std::tuple_size and std::tuple_element.