mathop.h File Reference
Detailed Description
Definition in file mathop.h.
#include "generic.h"
Go to the source code of this file.
ui16 | VL_FAST_SQRT_UI (vl_uint8, ui8) float vl_dist_l2_f(float *dist |
Auto distances. | |
Defines | |
#define | VL_LOG_OF_2 0.693147180559945 |
Logarithm of 2 (math constant). | |
#define | VL_PI 3.141592653589793 |
Pi (math constant). | |
#define | VL_EPSILON_F 1.19209290E-07F |
IEEE single precision epsilon (math constant). | |
#define | VL_EPSILON_D 2.220446049250313e-16 |
IEEE double precision epsilon (math constant). | |
#define | VL_NAN_F (vl_nan_f.value) |
IEEE single precision NaN (not signaling). | |
#define | VL_INFINITY_F (vl_infinity_f.value) |
IEEE single precision positive infinity (not signaling). | |
#define | VL_NAN_D (vl_nan_d.value) |
IEEE double precision NaN (not signaling). | |
#define | VL_INFINITY_D (vl_infinity_d.value) |
IEEE double precision positive infinity (not signaling). | |
Functions | |
VL_INLINE float | vl_mod_2pi_f (float x) |
Fast mod(x, 2 * VL_PI) . | |
VL_INLINE double | vl_mod_2pi_d (double x) |
Fast mod(x, 2 * VL_PI) . | |
VL_INLINE int | vl_floor_f (float x) |
Fast (int) floor(x) . | |
VL_INLINE int | vl_floor_d (double x) |
Fast (int) floor(x) . | |
VL_INLINE float | vl_abs_f (float x) |
Fast abs(x) . | |
VL_INLINE double | vl_abs_d (double x) |
Fast abs(x) . | |
VL_INLINE float | vl_fast_atan2_f (float y, float x) |
Fast atan2 approximation. | |
VL_INLINE double | vl_fast_atan2_d (double y, double x) |
Fast atan2 approximation. | |
VL_INLINE float | vl_fast_resqrt_f (float x) |
Fast resqrt approximation. | |
VL_INLINE double | vl_fast_resqrt_d (double x) |
Fast resqrt approximation. | |
VL_INLINE float | vl_fast_sqrt_f (float x) |
Fast sqrt approximation. | |
VL_INLINE double | vl_fast_sqrt_d (float x) |
Fast sqrt approximation. | |
VL_INLINE vl_uint32 | vl_fast_sqrt_ui32 (vl_uint32 x) |
Fast sqrt approximation. | |
VL_INLINE vl_uint16 | vl_fast_sqrt_ui16 (vl_uint16 x) |
Fast sqrt approximation. | |
VL_INLINE vl_uint8 | vl_fast_sqrt_ui8 (vl_uint8 x) |
Fast sqrt approximation. | |
Define Documentation
#define VL_EPSILON_D 2.220446049250313e-16 |
1.0 + VL_EPSILON_D
is the smallest representable double precision number greater than 1.0
. Numerically, VL_EPSILON_D is equal to .
Definition at line 39 of file mathop.h.
Referenced by vl_fast_atan2_d(), and vl_sift_calc_raw_descriptor().
#define VL_EPSILON_F 1.19209290E-07F |
1.0F + VL_EPSILON_F
is the smallest representable single precision number greater than 1.0F
. Numerically, VL_EPSILON_F is equal to .
Definition at line 31 of file mathop.h.
Referenced by _vl_dsift_normalize_histogram(), normalize_histogram(), vl_fast_atan2_f(), and vl_pgm_write_f().
Function Documentation
VL_INLINE double vl_abs_d | ( | double | x | ) |
- Parameters:
-
x argument.
- Returns:
abs(x)
Definition at line 162 of file mathop.h.
Referenced by vl_fast_atan2_d(), and vl_sift_detect().
VL_INLINE float vl_abs_f | ( | float | x | ) |
- Parameters:
-
x argument.
- Returns:
abs(x)
Definition at line 155 of file mathop.h.
Referenced by vl_fast_atan2_f(), vl_sift_calc_keypoint_descriptor(), and vl_sift_calc_raw_descriptor().
VL_INLINE double vl_fast_atan2_d | ( | double | y, | |
double | x | |||
) |
- Parameters:
-
y argument. x argument.
atan2(y,x)
.
- Algorithm

![$ r \in [-1,1] $](form_77.png)

The last degree of freedom is fixed by minimizing the error, which yields
with maximum error of 0.0061 radians at 0.35 degrees.
- Returns:
- Approximation of
atan2(y,x)
.
Definition at line 227 of file mathop.h.
References vl_abs_d(), VL_EPSILON_D, and VL_PI.
VL_INLINE float vl_fast_atan2_f | ( | float | y, | |
float | x | |||
) |
- Parameters:
-
y argument. x argument.
atan2(y,x)
.
- Algorithm

![$ r \in [-1,1] $](form_77.png)

The last degree of freedom is fixed by minimizing the error, which yields
with maximum error of 0.0061 radians at 0.35 degrees.
- Returns:
- Approximation of
atan2(y,x)
.
Definition at line 207 of file mathop.h.
References vl_abs_f(), VL_EPSILON_F, and VL_PI.
Referenced by vl_dsift_process().
VL_INLINE double vl_fast_resqrt_d | ( | double | x | ) |
- Parameters:
-
x argument.

- Algorithm


which yields a simple polynomial update rule.
The clever bit (attributed to either J. Carmack or G. Tarolli) is the way an initial guess is chosen.
- See also:
- Inverse Sqare Root.
- Returns:
- Approximation of
resqrt(x)
.
Definition at line 304 of file mathop.h.
Referenced by vl_fast_sqrt_d().
VL_INLINE float vl_fast_resqrt_f | ( | float | x | ) |
- Parameters:
-
x argument.

- Algorithm


which yields a simple polynomial update rule.
The clever bit (attributed to either J. Carmack or G. Tarolli) is the way an initial guess is chosen.
- See also:
- Inverse Sqare Root.
- Returns:
- Approximation of
resqrt(x)
.
Definition at line 279 of file mathop.h.
Referenced by vl_fast_sqrt_f().
VL_INLINE double vl_fast_sqrt_d | ( | float | x | ) |
- Parameters:
-
x argument.
sqrt(x)
.
- Floating-point algorithm
x * vl_fast_resqrt_f(x)
.
- Integer algorithm


Assume w known. Expanding the square and using the fact that , we obtain the following constraint for
and z:
A necessary condition for is that this equation is satisfied for
(as the second term is always non-negative). In fact, this condition is also sufficient, since we are looking for the largest solution y.
This yields the following iterative algorithm. First, note that if x is stored in n bits, where n is even, then the integer square root does not require more than bit to be stored. Thus initially,
and
. Then, at each iteration the equation is tested, determining
in this order.
- Returns:
- Approximation of
sqrt(x)
.
Definition at line 389 of file mathop.h.
References vl_fast_resqrt_d().
VL_INLINE float vl_fast_sqrt_f | ( | float | x | ) |
- Parameters:
-
x argument.
sqrt(x)
.
- Floating-point algorithm
x * vl_fast_resqrt_f(x)
.
- Integer algorithm


Assume w known. Expanding the square and using the fact that , we obtain the following constraint for
and z:
A necessary condition for is that this equation is satisfied for
(as the second term is always non-negative). In fact, this condition is also sufficient, since we are looking for the largest solution y.
This yields the following iterative algorithm. First, note that if x is stored in n bits, where n is even, then the integer square root does not require more than bit to be stored. Thus initially,
and
. Then, at each iteration the equation is tested, determining
in this order.
- Returns:
- Approximation of
sqrt(x)
.
Definition at line 382 of file mathop.h.
References vl_fast_resqrt_f().
Referenced by _vl_dsift_normalize_histogram(), normalize_histogram(), and vl_dsift_process().
ui16 VL_FAST_SQRT_UI | ( | vl_uint8 | , | |
ui8 | ||||
) |
- Parameters:
-
dist pointer to the distance matrix (out). M number of dimensions NX number of data points in X. NY number of data points in Y. X first data set. Y second data set.
- Parameters:
-
x argument.
sqrt(x)
.
- Floating-point algorithm
x * vl_fast_resqrt_f(x)
.
- Integer algorithm


Assume w known. Expanding the square and using the fact that , we obtain the following constraint for
and z:
A necessary condition for is that this equation is satisfied for
(as the second term is always non-negative). In fact, this condition is also sufficient, since we are looking for the largest solution y.
This yields the following iterative algorithm. First, note that if x is stored in n bits, where n is even, then the integer square root does not require more than bit to be stored. Thus initially,
and
. Then, at each iteration the equation is tested, determining
in this order.
- Returns:
- Approximation of
sqrt(x)
.
- Parameters:
-
x argument.
sqrt(x)
.
- Floating-point algorithm
x * vl_fast_resqrt_f(x)
.
- Integer algorithm


Assume w known. Expanding the square and using the fact that , we obtain the following constraint for
and z:
A necessary condition for is that this equation is satisfied for
(as the second term is always non-negative). In fact, this condition is also sufficient, since we are looking for the largest solution y.
This yields the following iterative algorithm. First, note that if x is stored in n bits, where n is even, then the integer square root does not require more than bit to be stored. Thus initially,
and
. Then, at each iteration the equation is tested, determining
in this order.
- Returns:
- Approximation of
sqrt(x)
.
- Parameters:
-
x argument.
sqrt(x)
.
- Floating-point algorithm
x * vl_fast_resqrt_f(x)
.
- Integer algorithm


Assume w known. Expanding the square and using the fact that , we obtain the following constraint for
and z:
A necessary condition for is that this equation is satisfied for
(as the second term is always non-negative). In fact, this condition is also sufficient, since we are looking for the largest solution y.
This yields the following iterative algorithm. First, note that if x is stored in n bits, where n is even, then the integer square root does not require more than bit to be stored. Thus initially,
and
. Then, at each iteration the equation is tested, determining
in this order.
- Returns:
- Approximation of
sqrt(x)
.
VL_INLINE int vl_floor_d | ( | double | x | ) |
- Parameters:
-
x argument.
- Returns:
(int) floor(x)
Definition at line 138 of file mathop.h.
Referenced by fast_expn(), vl_sift_calc_keypoint_orientations(), and vl_sift_keypoint_init().
VL_INLINE int vl_floor_f | ( | float | x | ) |
- Parameters:
-
x argument.
- Returns:
(int) floor(x)
Definition at line 129 of file mathop.h.
Referenced by vl_dsift_process(), vl_sift_calc_keypoint_descriptor(), and vl_sift_calc_raw_descriptor().
VL_INLINE double vl_mod_2pi_d | ( | double | x | ) |
- Parameters:
-
x input value.
The result is guaranteed not to be smaller than 0. However, due to finite numerical precision and rounding errors, the result can be equal to 2 * VL_PI (for instance, if x
is a very small negative number).
- Returns:
mod(x, 2 * VL_PI)
Definition at line 112 of file mathop.h.
References VL_PI.
VL_INLINE float vl_mod_2pi_f | ( | float | x | ) |
- Parameters:
-
x input value.
The result is guaranteed not to be smaller than 0. However, due to finite numerical precision and rounding errors, the result can be equal to 2 * VL_PI (for instance, if x
is a very small negative number).
- Returns:
mod(x, 2 * VL_PI)
Definition at line 104 of file mathop.h.
References VL_PI.
Referenced by vl_dsift_process(), vl_sift_calc_keypoint_descriptor(), and vl_sift_calc_raw_descriptor().