I am trying to define my own data type (called sfloat ), similar to float, but using a different number of mantissa bits and exponential bits to better match the data range and accuracy. The goal is to define a new data type that can replace float in existing applications. Everything still works, except that I could not override or define the unsigned operator in such a way that
unsigned sfloat(3.141527)
will return an unsigned version of this class, usfloat(3.141527) .
It seems that the unsigned specifier may be overloaded, since VS intellisense does not complain in the header file:
sfloat::sfloat(float f) { m_data = get16bit(f); } operator unsigned() { };
But it does not work in declaration and initialization:
unsigned sfloat myPi= 3.141527;
I donβt even know if it is possible to do this in C ++, and I wonder if someone has done this before?
source share