Implement to_float and set_float of F2DOT14 (#984)

This commit is contained in:
Ebrahim Byagowi 2018-04-15 22:08:50 +04:30 committed by GitHub
parent 435b1878e7
commit ce99dd04de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -683,8 +683,9 @@ typedef HBUINT16 UFWORD;
/* 16-bit signed fixed number with the low 14 bits of fraction (2.14). */ /* 16-bit signed fixed number with the low 14 bits of fraction (2.14). */
struct F2DOT14 : HBINT16 struct F2DOT14 : HBINT16
{ {
//inline float to_float (void) const { return ???; } // 16384 means 1<<14
//inline void set_float (float f) { v.set (f * ???); } inline float to_float (void) const { return ((int32_t) v) / 16384.0; }
inline void set_float (float f) { v.set (f * 16384.0); }
public: public:
DEFINE_SIZE_STATIC (2); DEFINE_SIZE_STATIC (2);
}; };
@ -692,6 +693,7 @@ struct F2DOT14 : HBINT16
/* 32-bit signed fixed-point number (16.16). */ /* 32-bit signed fixed-point number (16.16). */
struct Fixed : HBINT32 struct Fixed : HBINT32
{ {
// 65536 means 1<<16
inline float to_float (void) const { return ((int32_t) v) / 65536.0; } inline float to_float (void) const { return ((int32_t) v) / 65536.0; }
inline void set_float (float f) { v.set (round (f * 65536.0)); } inline void set_float (float f) { v.set (round (f * 65536.0)); }
public: public: