MU Library
half_float::detail::f31 Struct Reference

Class for 1.31 unsigned floating-point computation. More...

#include <half.hpp>

Public Member Functions

HALF_CONSTEXPR f31 (uint32 mant, int e)
 
 f31 (unsigned int abs)
 

Public Attributes

uint32 m
 mantissa as 1.31. More...
 
int exp
 exponent. More...
 

Friends

f31 operator+ (f31 a, f31 b)
 
f31 operator- (f31 a, f31 b)
 
f31 operator* (f31 a, f31 b)
 
f31 operator/ (f31 a, f31 b)
 

Detailed Description

Class for 1.31 unsigned floating-point computation.

Definition at line 4861 of file half.hpp.

Constructor & Destructor Documentation

◆ f31() [1/2]

HALF_CONSTEXPR half_float::detail::f31::f31 ( uint32  mant,
int  e 
)
inline

Constructor.

Parameters
mantmantissa as 1.31
eexponent

Definition at line 4866 of file half.hpp.

4866  : m(mant),
4867  exp(e)
4868  {
4869  }
4870 
int exp
exponent.
Definition: half.hpp:4935
uint32 m
mantissa as 1.31.
Definition: half.hpp:4934

◆ f31() [2/2]

half_float::detail::f31::f31 ( unsigned int  abs)
inline

Constructor.

Parameters
absunsigned half-precision value

Definition at line 4874 of file half.hpp.

4874  : exp(-15)
4875  {
4876  for (; abs < 0x400; abs <<= 1, --exp)
4877  ;
4878  m = static_cast<uint32>((abs & 0x3FF) | 0x400) << 21;
4879  exp += (abs >> 10);
4880  }
4881 
unsigned long uint32
Fastest unsigned integer of (at least) 32 bits width.
Definition: half.hpp:596
HALF_CONSTEXPR half abs(half arg)
Definition: half.hpp:5905

Friends And Related Function Documentation

◆ operator*

f31 operator* ( f31  a,
f31  b 
)
friend

Multiplication operator.

Parameters
afirst operand
bsecond operand
Returns
a * b

Definition at line 4916 of file half.hpp.

4916  {
4917  uint32 m = multiply64(a.m, b.m);
4918  int i = m >> 31;
4919  return f31(m << (1 - i), a.exp + b.exp + i);
4920  }
4921 
uint32 multiply64(uint32 x, uint32 y)
Definition: half.hpp:4259
HALF_CONSTEXPR f31(uint32 mant, int e)
Definition: half.hpp:4866

◆ operator+

f31 operator+ ( f31  a,
f31  b 
)
friend

Addition operator.

Parameters
afirst operand
bsecond operand
Returns
a + b

Definition at line 4887 of file half.hpp.

4887  {
4888  if (b.exp > a.exp)
4889  std::swap(a, b);
4890  int d = a.exp - b.exp;
4891  uint32 m = a.m + ((d < 32) ? (b.m >> d) : 0);
4892  int i = (m & 0xFFFFFFFF) < a.m;
4893  return f31(((m + i) >> i) | 0x80000000, a.exp + i);
4894  }
4895 

◆ operator-

f31 operator- ( f31  a,
f31  b 
)
friend

Subtraction operator.

Parameters
afirst operand
bsecond operand
Returns
a - b

Definition at line 4901 of file half.hpp.

4901  {
4902  int d = a.exp - b.exp, exp = a.exp;
4903  uint32 m = a.m - ((d < 32) ? (b.m >> d) : 0);
4904  if (!m)
4905  return f31(0, -32);
4906  for (; m < 0x80000000; m <<= 1, --exp)
4907  ;
4908  return f31(m, exp);
4909  }
4910 

◆ operator/

f31 operator/ ( f31  a,
f31  b 
)
friend

Division operator.

Parameters
afirst operand
bsecond operand
Returns
a / b

Definition at line 4927 of file half.hpp.

4927  {
4928  int i = a.m >= b.m, s;
4929  uint32 m = divide64((a.m + i) >> i, b.m, s);
4930  return f31(m, a.exp - b.exp + i - 1);
4931  }
4932 
uint32 divide64(uint32 x, uint32 y, int &s)
Definition: half.hpp:4273

Member Data Documentation

◆ exp

int half_float::detail::f31::exp

exponent.

Definition at line 4935 of file half.hpp.

◆ m

uint32 half_float::detail::f31::m

mantissa as 1.31.

Definition at line 4934 of file half.hpp.


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