Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add more double length functions to support vector_norm
  • Loading branch information
rhettinger committed Mar 15, 2023
commit cd5fb29fb43dfe4ad3c508aa98e16b768f03daa6
31 changes: 31 additions & 0 deletions Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,22 @@ Double and triple length extended precision algorithms from:

typedef struct{ double hi; double lo; } DoubleLength;

static DoubleLength
d_to_dl(double x)
{
return (DoubleLength) {x, 0.0};
}

static DoubleLength
dl_fast_sum(double a, double b)
{
/* Algorithm 1.1. Compensated summation of two floating point numbers. */
assert(fabs(a) >= fabs(b));
double x = a + b;
double y = (a - x) + b;
return (DoubleLength) {x, y};
}

static DoubleLength
dl_sum(double a, double b)
{
Expand Down Expand Up @@ -164,6 +180,21 @@ dl_mul(double x, double y)
return (DoubleLength) {z, zz};
}

static DoubleLength
dl_fma(double x, double y, DoubleLength total)
{
/* Algorithm 5.10 with SumKVert for K=2 */
DoubleLength pr = dl_mul(x, y);
DoubleLength sm = dl_sum(total.hi, pr.hi);
return DoubleLength {sm.hi, pr.lo + sm.lo + total.lo};
}

static double
dl_to_d(DoubleLength total):
{
return total.lo + total.hi;
}

#endif

typedef struct { double hi; double lo; double tiny; } TripleLength;
Expand Down