X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=fp16.h;h=4e6652f689fb79affad6bb5d0c3cc0765afa5a3c;hb=cea222cc88f1e210cd73331d74d0b33a67de3d81;hp=9f7eff926fca594d54198b14b3ec30d834124508;hpb=42f0fd5ccbb3560a76d55f3e725416a5e0f93523;p=movit diff --git a/fp16.h b/fp16.h index 9f7eff9..4e6652f 100644 --- a/fp16.h +++ b/fp16.h @@ -22,6 +22,22 @@ fp16_int_t fp64_to_fp16(double x); double fp32_to_fp64(fp32_int_t x); fp32_int_t fp64_to_fp32(double x); +// Overloads for use in templates. +static inline double to_fp64(double x) { return x; } +static inline double to_fp64(float x) { return x; } +static inline double to_fp64(fp16_int_t x) { return fp16_to_fp64(x); } + +template inline T from_fp64(double x); +template<> inline double from_fp64(double x) { return x; } +template<> inline float from_fp64(double x) { return x; } +template<> inline fp16_int_t from_fp64(double x) { return fp64_to_fp16(x); } + +template +inline To convert_float(From x) { return from_fp64(to_fp64(x)); } + +template +inline Same convert_float(Same x) { return x; } + } // namespace movit #endif // _MOVIT_FP16_H