Math operations - Definition. More...
#include "mathop.h"
#include "mathop_sse2.h"
#include "mathop_avx.h"
#include <math.h>
#include "mathop.c"
#include "float.th"
Go to the source code of this file.
Defines | |
#define | COMPARISONFUNCTION3_TYPE VlDoubleVector3ComparisonFunction |
#define | COMPARISONFUNCTION_TYPE VlDoubleVectorComparisonFunction |
#define | FLT VL_TYPE_FLOAT |
#define | FLT VL_TYPE_DOUBLE |
#define | VL_MATHOP_INSTANTIATING |
#define | VL_MATHOP_INSTANTIATING |
Functions | |
VL_EXPORT | T (vl_size dimension, T const *X, T const *Y) |
VL_EXPORT | T (vl_size dimension, T const *X, T const *MU, T const *S) |
VL_EXPORT COMPARISONFUNCTION_TYPE | VL_XCAT (vl_get_vector_comparison_function_, SFX) |
VL_EXPORT COMPARISONFUNCTION3_TYPE | VL_XCAT (vl_get_vector_3_comparison_function_, SFX) |
VL_EXPORT | void (T *result, vl_size dimension, T const *X, vl_size numDataX, T const *Y, vl_size numDataY, COMPARISONFUNCTION_TYPE function) |
Math operations - Definition.
Definition in file mathop.c.
#define FLT VL_TYPE_FLOAT |
$ is the bit to be determined. Here $y_{k+1}$ is a part of the result $y$ that has already been determined, while the bit $q$ and the remainder $r$ are still unknown. Recall that the goal is to find the largest $y^2$ such that $y^2 x$. Expanding $y^2$ this condition becomes
\[ q (2^{2k} + 2 y_{k+1} 2^k) + r(r + 2q 2^k + 2 y_{k+1}) x - y_{k+1}^2. \]
We can now determine if $q=1$ or $q=0$ based on the value of the residual $x - y_{k+1}^2$. Specifically, $q=1$ requires that:
\[ { 2^{2k} + 2a2^k x - y_{k+1}^2. } \]
On the other hand, if this equation is satisfied, then setting $r=0$ shows that there exists at least one $y$ such that $q=1$ and $y^2 x$. In particular, greedily choosing $q=1$ in $x=y_{k+1} + 2^k q + r$ is optimal because $2^k > r$. This yields the algorithm:
1. Note that if $x$ is stored in $n$ bits and $n$ is even, then the integer square root $y$ does not require more than $m = n / 2$ bit to be stored. Thus the first bit to be determined is $k m - 1 = n/2 - 1$ and $y_{n/2}=0$. 2. The algorithm stores and updates $y_k/2^{k}$ and $x - y_{k}^2$ for convenience. 3. During iteration $k$, $y_k$ is determined. On entering the iteration, the first step is to compute $y_{k+1}/2^k = 2 y_{k+1}/2^{k+1}$. 4. Then the bound $t = (2^{2k} + 2 y_{k+1})2^k = 2^{2k}(1 + 2 y_{k+1}/2^k)$. 5. If $t x - y_{k+1}$, the $k$-th bit of $y_k$ is set to one. This means applying the update $ y_{k}/2^k y_{k+1}/2^k + 1$. This also requires computing $x - y_{k}^2 x - y_{k+1}^2 - t$. 6. Decrement $k k -1$ and, if $k 0$, continue from 3.
#define FLT VL_TYPE_DOUBLE |
$ is the bit to be determined. Here $y_{k+1}$ is a part of the result $y$ that has already been determined, while the bit $q$ and the remainder $r$ are still unknown. Recall that the goal is to find the largest $y^2$ such that $y^2 x$. Expanding $y^2$ this condition becomes
\[ q (2^{2k} + 2 y_{k+1} 2^k) + r(r + 2q 2^k + 2 y_{k+1}) x - y_{k+1}^2. \]
We can now determine if $q=1$ or $q=0$ based on the value of the residual $x - y_{k+1}^2$. Specifically, $q=1$ requires that:
\[ { 2^{2k} + 2a2^k x - y_{k+1}^2. } \]
On the other hand, if this equation is satisfied, then setting $r=0$ shows that there exists at least one $y$ such that $q=1$ and $y^2 x$. In particular, greedily choosing $q=1$ in $x=y_{k+1} + 2^k q + r$ is optimal because $2^k > r$. This yields the algorithm:
1. Note that if $x$ is stored in $n$ bits and $n$ is even, then the integer square root $y$ does not require more than $m = n / 2$ bit to be stored. Thus the first bit to be determined is $k m - 1 = n/2 - 1$ and $y_{n/2}=0$. 2. The algorithm stores and updates $y_k/2^{k}$ and $x - y_{k}^2$ for convenience. 3. During iteration $k$, $y_k$ is determined. On entering the iteration, the first step is to compute $y_{k+1}/2^k = 2 y_{k+1}/2^{k+1}$. 4. Then the bound $t = (2^{2k} + 2 y_{k+1})2^k = 2^{2k}(1 + 2 y_{k+1}/2^k)$. 5. If $t x - y_{k+1}$, the $k$-th bit of $y_k$ is set to one. This means applying the update $ y_{k}/2^k y_{k+1}/2^k + 1$. This also requires computing $x - y_{k}^2 x - y_{k+1}^2 - t$. 6. Decrement $k k -1$ and, if $k 0$, continue from 3.
#define VL_MATHOP_INSTANTIATING |
#define VL_MATHOP_INSTANTIATING |
VL_EXPORT COMPARISONFUNCTION_TYPE VL_XCAT | ( | vl_get_vector_comparison_function_ | , |
SFX | |||
) |
VL_EXPORT COMPARISONFUNCTION3_TYPE VL_XCAT | ( | vl_get_vector_3_comparison_function_ | , |
SFX | |||
) |