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.
Classes#
Name |
Description |
|---|---|
|
|
|
Functions#
Return |
Name |
Description |
|---|---|---|
Default constructor. |
||
|
Construct from double. |
|
|
||
|
||
|
Copy constructor. |
|
|
Construct from integer. |
|
|
||
Default constructor. |
||
|
Construct from float. |
|
|
||
|
||
|
Copy constructor. |
|
|
Construct from integer. |
|
|
||
Absolute value. |
||
Cube root. |
||
|
Cosine. |
|
|
|
Difference between 1 and next representable value. |
|
|
Difference between 1 and next representable value. |
|
||
Exponent. |
||
|
|
Construct from raw. |
|
|
Construct from raw. |
|
Get 0-based exponent. |
|
|
Get 0-based exponent. |
|
Get a fraction part. |
||
Get a fraction part. |
||
|
Get sign bit. |
|
|
Get sign bit. |
|
|
|
Positive infinity constant. |
|
|
Positive infinity constant. |
|
Inf state indicator. |
|
|
Inf state indicator. |
|
|
NaN state indicator. |
|
|
NaN state indicator. |
|
|
Subnormal number indicator. |
|
|
Subnormal number indicator. |
|
|
||
Natural logarithm. |
||
|
||
|
|
Biggest finite value. |
|
|
Biggest finite value. |
|
||
Min and Max functions. |
||
|
|
Smallest normalized value. |
|
|
Smallest normalized value. |
|
||
|
Fused Multiplication and Addition. |
|
|
|
Default NaN constant. |
|
|
Default NaN constant. |
|
|
One constant. |
|
|
One constant. |
Type casts |
||
Type casts |
||
|
|
|
|
|
|
|
Remainder operator. |
|
|
Remainder operator. |
|
|
||
|
||
|
||
|
||
|
||
|
||
|
Basic arithmetics. |
|
|
Basic arithmetics. |
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
Assign constructor. |
|
|
Assign constructor. |
|
|
|
Comparison operations. |
|
|
Comparison operations. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Correct pi approximation. |
|
|
Correct pi approximation. |
|
||
Raising to the power. |
||
|
||
|
Saturate casts. |
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Saturate cast to unsigned integer and unsigned long long integer We intentionally do not clip negative numbers, to make -1 become 0xffffffff etc. |
|
|
Construct a copy with new 0-based exponent. |
|
|
Construct a copy with new 0-based exponent. |
|
|
Construct a copy with provided significand. |
|
|
Construct a copy with provided significand. |
|
|
Construct a copy with new sign bit. |
|
|
Construct a copy with new sign bit. |
|
|
Sine. |
|
|
||
Square root. |
||
|
|
Zero constant. |
|
|
Zero constant. |
Variables#
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.