Softfloat support#

Detailed Description#

SoftFloat is a software implementation of floating-point calculations according to IEEE 754 standard. All calculations are done in integers, that’s why they are machine-independent and bit-exact. This library can be useful in accuracy-critical parts like look-up tables generation, tests, etc. OpenCV contains a subset of SoftFloat partially rewritten to C++.

Types#

There are two basic types: softfloat and softdouble. These types are binary compatible with float and double types respectively and support conversions to/from them. Other types from original SoftFloat library like fp16 or fp128 were thrown away as well as quiet/signaling NaN support, on-the-fly rounding mode switch and exception flags (though exceptions can be implemented in the future).

Operations#

Both types support the following:

  • Construction from signed and unsigned 32-bit and 64 integers, float/double or raw binary representation

  • Conversions between each other, to float or double and to int using cvRound, cvTrunc, cvFloor, cvCeil or a bunch of saturate_cast functions

  • Add, subtract, multiply, divide, remainder, square root, FMA with absolute precision

  • Comparison operations

  • Explicit sign, exponent and significand manipulation through get/set methods, number state indicators (isInf, isNan, isSubnormal)

  • Type-specific constants like eps, minimum/maximum value, best pi approximation, etc.

  • min(), max(), abs(), exp(), log() and pow() functions

Classes#

Name

Description

struct cv::softdouble

View details

struct cv::softfloat

View details

Functions#

Return

Name

Description

cv::softdouble()

Default constructor.

cv::softdouble(const double a)

Construct from double.

cv::softdouble(const int32_t )

cv::softdouble(const int64_t )

cv::softdouble(const softdouble & c)

Copy constructor.

cv::softdouble(const uint32_t )

Construct from integer.

cv::softdouble(const uint64_t )

cv::softfloat()

Default constructor.

cv::softfloat(const float a)

Construct from float.

cv::softfloat(const int32_t )

cv::softfloat(const int64_t )

cv::softfloat(const softfloat & c)

Copy constructor.

cv::softfloat(const uint32_t )

Construct from integer.

cv::softfloat(const uint64_t )

softdouble

cv::abs(softdouble a)

softfloat

cv::abs(softfloat a)

Absolute value.

softfloat

cv::cbrt(const softfloat & a)

Cube root.

softdouble

cv::cos(const softdouble & a)

Cosine.

static softdouble

cv::eps()

Difference between 1 and next representable value.

static softfloat

cv::eps()

Difference between 1 and next representable value.

softdouble

cv::exp(const softdouble & a)

softfloat

cv::exp(const softfloat & a)

Exponent.

static softdouble

cv::fromRaw(const uint64_t a)

Construct from raw.

static const softfloat

cv::fromRaw(const uint32_t a)

Construct from raw.

int

cv::getExp()

Get 0-based exponent.

int

cv::getExp()

Get 0-based exponent.

softdouble

cv::getFrac()

Get a fraction part.

softfloat

cv::getFrac()

Get a fraction part.

bool

cv::getSign()

Get sign bit.

bool

cv::getSign()

Get sign bit.

static softdouble

cv::inf()

Positive infinity constant.

static softfloat

cv::inf()

Positive infinity constant.

bool

cv::isInf()

Inf state indicator.

bool

cv::isInf()

Inf state indicator.

bool

cv::isNaN()

NaN state indicator.

bool

cv::isNaN()

NaN state indicator.

bool

cv::isSubnormal()

Subnormal number indicator.

bool

cv::isSubnormal()

Subnormal number indicator.

softdouble

cv::log(const softdouble & a)

softfloat

cv::log(const softfloat & a)

Natural logarithm.

softdouble

cv::max(
const softdouble & a,
const softdouble & b )

softfloat

cv::max(
const softfloat & a,
const softfloat & b )

static softdouble

cv::max()

Biggest finite value.

static softfloat

cv::max()

Biggest finite value.

softdouble

cv::min(
const softdouble & a,
const softdouble & b )

softfloat

cv::min(
const softfloat & a,
const softfloat & b )

Min and Max functions.

static softdouble

cv::min()

Smallest normalized value.

static softfloat

cv::min()

Smallest normalized value.

softdouble

cv::mulAdd(
const softdouble & a,
const softdouble & b,
const softdouble & c )

softfloat

cv::mulAdd(
const softfloat & a,
const softfloat & b,
const softfloat & c )

Fused Multiplication and Addition.

static softdouble

cv::nan()

Default NaN constant.

static softfloat

cv::nan()

Default NaN constant.

static softdouble

cv::one()

One constant.

static softfloat

cv::one()

One constant.

cv::operator double()

cv::operator float()

cv::operator softdouble()

Type casts

cv::operator softfloat()

Type casts

bool

cv::operator!=(const softdouble & )

bool

cv::operator!=(const softfloat & )

softdouble

cv::operator%(const softdouble & )

Remainder operator.

softfloat

cv::operator%(const softfloat & )

Remainder operator.

softdouble &

cv::operator%=(const softdouble & a)

softfloat &

cv::operator%=(const softfloat & a)

softdouble

cv::operator*(const softdouble & )

softfloat

cv::operator*(const softfloat & )

softdouble &

cv::operator*=(const softdouble & a)

softfloat &

cv::operator*=(const softfloat & a)

softdouble

cv::operator+(const softdouble & )

Basic arithmetics.

softfloat

cv::operator+(const softfloat & )

Basic arithmetics.

softdouble &

cv::operator+=(const softdouble & a)

softfloat &

cv::operator+=(const softfloat & a)

softdouble

cv::operator-()

softdouble

cv::operator-(const softdouble & )

softfloat

cv::operator-()

softfloat

cv::operator-(const softfloat & )

softdouble &

cv::operator-=(const softdouble & a)

softfloat &

cv::operator-=(const softfloat & a)

softdouble

cv::operator/(const softdouble & )

softfloat

cv::operator/(const softfloat & )

softdouble &

cv::operator/=(const softdouble & a)

softfloat &

cv::operator/=(const softfloat & a)

bool

cv::operator<(const softdouble & )

bool

cv::operator<(const softfloat & )

bool

cv::operator<=(const softdouble & )

bool

cv::operator<=(const softfloat & )

softdouble &

cv::operator=(const softdouble & c)

Assign constructor.

softfloat &

cv::operator=(const softfloat & c)

Assign constructor.

bool

cv::operator==(const softdouble & )

Comparison operations.

bool

cv::operator==(const softfloat & )

Comparison operations.

bool

cv::operator>(const softdouble & )

bool

cv::operator>(const softfloat & )

bool

cv::operator>=(const softdouble & )

bool

cv::operator>=(const softfloat & )

static softdouble

cv::pi()

Correct pi approximation.

static softfloat

cv::pi()

Correct pi approximation.

softdouble

cv::pow(
const softdouble & a,
const softdouble & b )

softfloat

cv::pow(
const softfloat & a,
const softfloat & b )

Raising to the power.

template<typename _Tp>
static _Tp

cv::saturate_cast(softdouble a)

template<typename _Tp>
static _Tp

cv::saturate_cast(softfloat a)

Saturate casts.

int64_t

cv::saturate_cast< int64_t >(softdouble a)

int64_t

cv::saturate_cast< int64_t >(softfloat a)

schar

cv::saturate_cast< schar >(softdouble a)

schar

cv::saturate_cast< schar >(softfloat a)

short

cv::saturate_cast< short >(softdouble a)

short

cv::saturate_cast< short >(softfloat a)

uchar

cv::saturate_cast< uchar >(softdouble a)

uchar

cv::saturate_cast< uchar >(softfloat a)

uint64_t

cv::saturate_cast< uint64_t >(softdouble a)

uint64_t

cv::saturate_cast< uint64_t >(softfloat a)

unsigned

cv::saturate_cast< unsigned >(softdouble a)

unsigned

cv::saturate_cast< unsigned >(softfloat a)

Saturate cast to unsigned integer and unsigned long long integer We intentionally do not clip negative numbers, to make -1 become 0xffffffff etc.

ushort

cv::saturate_cast< ushort >(softdouble a)

ushort

cv::saturate_cast< ushort >(softfloat a)

softdouble

cv::setExp(int e)

Construct a copy with new 0-based exponent.

softfloat

cv::setExp(int e)

Construct a copy with new 0-based exponent.

softdouble

cv::setFrac(const softdouble & s)

Construct a copy with provided significand.

softfloat

cv::setFrac(const softfloat & s)

Construct a copy with provided significand.

softdouble

cv::setSign(bool sign)

Construct a copy with new sign bit.

softfloat

cv::setSign(bool sign)

Construct a copy with new sign bit.

softdouble

cv::sin(const softdouble & a)

Sine.

softdouble

cv::sqrt(const softdouble & a)

softfloat

cv::sqrt(const softfloat & a)

Square root.

static softdouble

cv::zero()

Zero constant.

static softfloat

cv::zero()

Zero constant.

Variables#

Type

Name

Description

uint64_t

v

uint32_t

v

Function Documentation#

abs() [1/2]#

inline softdouble cv::abs(softdouble a)

#include <opencv2/core/softfloat.hpp>

abs() [2/2]#

inline softfloat cv::abs(softfloat a)

#include <opencv2/core/softfloat.hpp>

Absolute value.

cbrt()#

softfloat cv::cbrt(const softfloat & a)

#include <opencv2/core/softfloat.hpp>

Cube root.

Special cases:

  • cbrt(NaN) is NaN

  • cbrt(+/-Inf) is +/-Inf

cos()#

softdouble cv::cos(const softdouble & a)

#include <opencv2/core/softfloat.hpp>

Cosine.

Special cases:

  • cos(Inf) or cos(NaN) is NaN

  • cos(x) == +/- 1 when cos(x) is close to +/- 1

exp() [1/2]#

softdouble cv::exp(const softdouble & a)

#include <opencv2/core/softfloat.hpp>

exp() [2/2]#

softfloat cv::exp(const softfloat & a)

#include <opencv2/core/softfloat.hpp>

Exponent.

Special cases:

  • exp(NaN) is NaN

  • exp(-Inf) == 0

  • exp(+Inf) == +Inf

log() [1/2]#

softdouble cv::log(const softdouble & a)

#include <opencv2/core/softfloat.hpp>

log() [2/2]#

softfloat cv::log(const softfloat & a)

#include <opencv2/core/softfloat.hpp>

Natural logarithm.

Special cases:

  • log(NaN), log(x < 0) are NaN

  • log(0) == -Inf

max() [1/2]#

inline softdouble cv::max(
const softdouble & a,
const softdouble & b )

#include <opencv2/core/softfloat.hpp>

max() [2/2]#

inline softfloat cv::max(
const softfloat & a,
const softfloat & b )

#include <opencv2/core/softfloat.hpp>

min() [1/2]#

inline softdouble cv::min(
const softdouble & a,
const softdouble & b )

#include <opencv2/core/softfloat.hpp>

min() [2/2]#

inline softfloat cv::min(
const softfloat & a,
const softfloat & b )

#include <opencv2/core/softfloat.hpp>

Min and Max functions.

mulAdd() [1/2]#

softdouble cv::mulAdd(
const softdouble & a,
const softdouble & b,
const softdouble & c )

#include <opencv2/core/softfloat.hpp>

mulAdd() [2/2]#

softfloat cv::mulAdd(
const softfloat & a,
const softfloat & b,
const softfloat & c )

#include <opencv2/core/softfloat.hpp>

Fused Multiplication and Addition.

Computes (a*b)+c with single rounding

pow() [1/2]#

softdouble cv::pow(
const softdouble & a,
const softdouble & b )

#include <opencv2/core/softfloat.hpp>

pow() [2/2]#

softfloat cv::pow(
const softfloat & a,
const softfloat & b )

#include <opencv2/core/softfloat.hpp>

Raising to the power.

Special cases:

  • x**NaN is NaN for any x

  • ( |x| == 1 )**Inf is NaN

  • ( |x| > 1 )+Inf or ( |x| < 1 )-Inf is +Inf

  • ( |x| > 1 )-Inf or ( |x| < 1 )+Inf is 0

  • x ** 0 == 1 for any x

  • x ** 1 == 1 for any x

  • NaN ** y is NaN for any other y

  • Inf**(y < 0) == 0

  • Inf ** y is +Inf for any other y

  • (x < 0)**y is NaN for any other y if x can’t be correctly rounded to integer

  • 0 ** 0 == 1

  • 0 ** (y < 0) is +Inf

  • 0 ** (y > 0) is 0

saturate_cast() [1/2]#

template<typename _Tp>
static inline _Tp cv::saturate_cast(softdouble a)

#include <opencv2/core/softfloat.hpp>

saturate_cast() [2/2]#

template<typename _Tp>
static inline _Tp cv::saturate_cast(softfloat a)

#include <opencv2/core/softfloat.hpp>

Saturate casts.

sin()#

softdouble cv::sin(const softdouble & a)

#include <opencv2/core/softfloat.hpp>

Sine.

Special cases:

  • sin(Inf) or sin(NaN) is NaN

  • sin(x) == x when sin(x) is close to zero

sqrt() [1/2]#

softdouble cv::sqrt(const softdouble & a)

#include <opencv2/core/softfloat.hpp>

sqrt() [2/2]#

softfloat cv::sqrt(const softfloat & a)

#include <opencv2/core/softfloat.hpp>

Square root.