Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Macros | Functions
SkFloatBits.h File Reference
#include "include/private/base/SkMath.h"
#include <cstdint>
#include <cstring>

Go to the source code of this file.

Macros

#define SkScalarAs2sCompliment(x)   SkFloatAs2sCompliment(x)
 

Functions

static int32_t SkSignBitTo2sCompliment (int32_t x)
 
static int32_t Sk2sComplimentToSignBit (int32_t x)
 
static uint32_t SkFloat2Bits (float value)
 
static float SkBits2Float (uint32_t bits)
 
static int32_t SkFloatAs2sCompliment (float x)
 
static float Sk2sComplimentAsFloat (int32_t x)
 

Macro Definition Documentation

◆ SkScalarAs2sCompliment

#define SkScalarAs2sCompliment (   x)    SkFloatAs2sCompliment(x)

Definition at line 72 of file SkFloatBits.h.

Function Documentation

◆ Sk2sComplimentAsFloat()

static float Sk2sComplimentAsFloat ( int32_t  x)
inlinestatic

Return the 2s compliment int as a float. This undos the result of SkFloatAs2sCompliment

Definition at line 66 of file SkFloatBits.h.

66 {
67 return SkBits2Float((uint32_t)Sk2sComplimentToSignBit(x));
68}
static int32_t Sk2sComplimentToSignBit(int32_t x)
Definition SkFloatBits.h:31
static float SkBits2Float(uint32_t bits)
Definition SkFloatBits.h:48
double x

◆ Sk2sComplimentToSignBit()

static int32_t Sk2sComplimentToSignBit ( int32_t  x)
inlinestatic

Convert a 2s compliment int to a sign-bit (i.e. int interpreted as float). This undoes the result of SkSignBitTo2sCompliment().

Definition at line 31 of file SkFloatBits.h.

31 {
32 int sign = x >> 31;
33 // make x positive
34 x = (x ^ sign) - sign;
35 // set the sign bit as needed
36 x |= SkLeftShift(sign, 31);
37 return x;
38}
static constexpr int32_t SkLeftShift(int32_t value, int32_t shift)
Definition SkMath.h:37
static int sign(SkScalar x)
Definition SkPath.cpp:2141

◆ SkBits2Float()

static float SkBits2Float ( uint32_t  bits)
inlinestatic

Definition at line 48 of file SkFloatBits.h.

48 {
49 float value;
50 memcpy(&value, &bits, sizeof(float));
51 return value;
52}
uint8_t value

◆ SkFloat2Bits()

static uint32_t SkFloat2Bits ( float  value)
inlinestatic

Definition at line 41 of file SkFloatBits.h.

41 {
42 uint32_t bits;
43 memcpy(&bits, &value, sizeof(uint32_t));
44 return bits;
45}

◆ SkFloatAs2sCompliment()

static int32_t SkFloatAs2sCompliment ( float  x)
inlinestatic

Return the float as a 2s compliment int. Just to be used to compare floats to each other or against positive float-bit-constants (like 0). This does not return the int equivalent of the float, just something cheaper for compares-only.

Definition at line 59 of file SkFloatBits.h.

59 {
60 return SkSignBitTo2sCompliment((int32_t)SkFloat2Bits(x));
61}
static uint32_t SkFloat2Bits(float value)
Definition SkFloatBits.h:41
static int32_t SkSignBitTo2sCompliment(int32_t x)
Definition SkFloatBits.h:20

◆ SkSignBitTo2sCompliment()

static int32_t SkSignBitTo2sCompliment ( int32_t  x)
inlinestatic

Convert a sign-bit int (i.e. float interpreted as int) into a 2s compliement int. This also converts -0 (0x80000000) to 0. Doing this to a float allows it to be compared using normal C operators (<, <=, etc.)

Definition at line 20 of file SkFloatBits.h.

20 {
21 if (x < 0) {
22 x &= 0x7FFFFFFF;
23 x = -x;
24 }
25 return x;
26}