123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- #ifndef HALF_H
- #define HALF_H
- #include <assert.h>
- #include <stdint.h>
- #include <iostream>
- #define HALF_MAX 65504
- #define HALF_MIN -65504
- #define HALF_PRECISION 0.000001
- #define DIFF_SCALE 10000
- typedef union {
- int32_t i;
- float f;
- } _bit32_u;
- class half {
- friend std::ostream& operator<<(std::ostream& out, const half& c);
- friend std::istream& operator>>(std::istream& in, half& c);
- public:
- half();
- ~half();
- half(const float a);
-
- explicit operator int();
- explicit operator float();
- explicit operator double();
-
- friend half operator+(const int& a, const half& b);
- half& operator=(const half& a);
- half operator-(void);
- half operator+(const half& a);
- half operator-(const half& a);
- half operator*(const half& a);
- half operator/(const half& a);
- half& operator+=(const half& a);
- half& operator-=(const half& a);
- half& operator*=(const half& a);
- half& operator/=(const half& a);
- bool operator<(const half& a);
- bool operator<=(const half& a);
- bool operator>(const half& a);
- bool operator>=(const half& a);
- bool operator==(const half& a);
- bool operator!=(const half& a);
- static uint16_t float2half(const float a);
- static float half2float(const uint16_t a);
- uint16_t data_;
- };
- #endif
|