Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | Static Public Attributes | List of all members
SkFloatingPoint< RawType, ULPs > Class Template Reference

#include <SkFloatUtils.h>

Public Types

typedef SkTypeWithSize< sizeof(RawType) *CHAR_BIT >::UInt Bits
 

Public Member Functions

 SkFloatingPoint (const RawType &x)
 
Bits exponent_bits () const
 
Bits fraction_bits () const
 
bool is_nan () const
 
bool AlmostEquals (const SkFloatingPoint &rhs) const
 

Static Public Attributes

static const size_t kBitCount = CHAR_BIT * sizeof(RawType)
 
static const size_t kFractionBitCount = SkNumericLimits<RawType>::digits - 1
 
static const size_t kExponentBitCount = kBitCount - 1 - kFractionBitCount
 
static const Bits kSignBitMask = static_cast<Bits>(1) << (kBitCount - 1)
 
static const Bits kFractionBitMask
 
static const Bits kExponentBitMask = ~(kSignBitMask | kFractionBitMask)
 
static const size_t kMaxUlps = ULPs
 

Detailed Description

template<typename RawType, unsigned int ULPs>
class SkFloatingPoint< RawType, ULPs >

Definition at line 55 of file SkFloatUtils.h.

Member Typedef Documentation

◆ Bits

template<typename RawType , unsigned int ULPs>
typedef SkTypeWithSize<sizeof(RawType)*CHAR_BIT>::UInt SkFloatingPoint< RawType, ULPs >::Bits

Bits is a unsigned integer the same size as the floating point number.

Definition at line 58 of file SkFloatUtils.h.

Constructor & Destructor Documentation

◆ SkFloatingPoint()

template<typename RawType , unsigned int ULPs>
SkFloatingPoint< RawType, ULPs >::SkFloatingPoint ( const RawType &  x)
inlineexplicit

Constructs a FloatingPoint from a raw floating-point number.

On an Intel CPU, passing a non-normalized NAN (Not a Number) around may change its bits, although the new value is guaranteed to be also a NAN. Therefore, don't expect this constructor to preserve the bits in x when x is a NAN.

Definition at line 90 of file SkFloatUtils.h.

90{ fU.value = x; }
double x

Member Function Documentation

◆ AlmostEquals()

template<typename RawType , unsigned int ULPs>
bool SkFloatingPoint< RawType, ULPs >::AlmostEquals ( const SkFloatingPoint< RawType, ULPs > &  rhs) const
inline

Returns true iff this number is at most kMaxUlps ULP's away from ths. In particular, this function:

  • returns false if either number is (or both are) NAN.
  • treats really large numbers as almost equal to infinity.
  • thinks +0.0 and -0.0 are 0 DLP's apart.

Definition at line 113 of file SkFloatUtils.h.

113 {
114 // Any comparison operation involving a NAN must return false.
115 if (is_nan() || rhs.is_nan()) return false;
116
117 const Bits dist = DistanceBetweenSignAndMagnitudeNumbers(fU.bits,
118 rhs.fU.bits);
119 //SkDEBUGF("(%f, %f, %d) ", u_.value_, rhs.u_.value_, dist);
120 return dist <= kMaxUlps;
121 }
SkTypeWithSize< sizeof(RawType) *CHAR_BIT >::UInt Bits
Definition: SkFloatUtils.h:58
bool is_nan() const
Definition: SkFloatUtils.h:99
static const size_t kMaxUlps
Definition: SkFloatUtils.h:80

◆ exponent_bits()

template<typename RawType , unsigned int ULPs>
Bits SkFloatingPoint< RawType, ULPs >::exponent_bits ( ) const
inline

Returns the exponent bits of this number.

Definition at line 93 of file SkFloatUtils.h.

93{ return kExponentBitMask & fU.bits; }
static const Bits kExponentBitMask
Definition: SkFloatUtils.h:77

◆ fraction_bits()

template<typename RawType , unsigned int ULPs>
Bits SkFloatingPoint< RawType, ULPs >::fraction_bits ( ) const
inline

Returns the fraction bits of this number.

Definition at line 96 of file SkFloatUtils.h.

96{ return kFractionBitMask & fU.bits; }
static const Bits kFractionBitMask
Definition: SkFloatUtils.h:73

◆ is_nan()

template<typename RawType , unsigned int ULPs>
bool SkFloatingPoint< RawType, ULPs >::is_nan ( ) const
inline

Returns true iff this is NAN (not a number).

Definition at line 99 of file SkFloatUtils.h.

99 {
100 // It's a NAN if both of the folloowing are true:
101 // * the exponent bits are all ones
102 // * the fraction bits are not all zero.
103 return (exponent_bits() == kExponentBitMask) && (fraction_bits() != 0);
104 }
Bits exponent_bits() const
Definition: SkFloatUtils.h:93
Bits fraction_bits() const
Definition: SkFloatUtils.h:96

Member Data Documentation

◆ kBitCount

template<typename RawType , unsigned int ULPs>
const size_t SkFloatingPoint< RawType, ULPs >::kBitCount = CHAR_BIT * sizeof(RawType)
static

of bits in a number.

Definition at line 61 of file SkFloatUtils.h.

◆ kExponentBitCount

template<typename RawType , unsigned int ULPs>
const size_t SkFloatingPoint< RawType, ULPs >::kExponentBitCount = kBitCount - 1 - kFractionBitCount
static

of exponent bits in a number.

Definition at line 67 of file SkFloatUtils.h.

◆ kExponentBitMask

template<typename RawType , unsigned int ULPs>
const Bits SkFloatingPoint< RawType, ULPs >::kExponentBitMask = ~(kSignBitMask | kFractionBitMask)
static

The mask for the exponent bits.

Definition at line 77 of file SkFloatUtils.h.

◆ kFractionBitCount

template<typename RawType , unsigned int ULPs>
const size_t SkFloatingPoint< RawType, ULPs >::kFractionBitCount = SkNumericLimits<RawType>::digits - 1
static

of fraction bits in a number.

Definition at line 64 of file SkFloatUtils.h.

◆ kFractionBitMask

template<typename RawType , unsigned int ULPs>
const Bits SkFloatingPoint< RawType, ULPs >::kFractionBitMask
static
Initial value:
=
~static_cast<Bits>(0) >> (kExponentBitCount + 1)
static const size_t kExponentBitCount
Definition: SkFloatUtils.h:67

The mask for the fraction bits.

Definition at line 73 of file SkFloatUtils.h.

◆ kMaxUlps

template<typename RawType , unsigned int ULPs>
const size_t SkFloatingPoint< RawType, ULPs >::kMaxUlps = ULPs
static

How many ULP's (Units in the Last Place) to tolerate when comparing.

Definition at line 80 of file SkFloatUtils.h.

◆ kSignBitMask

template<typename RawType , unsigned int ULPs>
const Bits SkFloatingPoint< RawType, ULPs >::kSignBitMask = static_cast<Bits>(1) << (kBitCount - 1)
static

The mask for the sign bit.

Definition at line 70 of file SkFloatUtils.h.


The documentation for this class was generated from the following file: