Packages
mmath
0.2.7
0.2.26
0.2.25
0.2.24
0.2.23
0.2.22
0.2.21
0.2.20
0.2.19
0.2.18
0.2.17
0.2.16
0.2.15
0.2.14
0.2.13
0.2.12
0.2.11
0.2.10
0.2.9
0.2.8
0.2.7
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.2.0-alpha9
0.2.0-alpha8
0.2.0-alpha7
0.2.0-alpha6
0.2.0-alpha5
0.2.0-alpha4
0.2.0-alpha3
0.2.0-alpha2
0.2.0-alpha10
0.2.0-alpha1
0.2.0-alpha
0.1.17-alpha
0.1.16
0.1.15
0.1.14
0.1.13
0.1.11
0.1.10
0.1.9
0.1.8
0.1.7
0.1.6
math library for metric sequences and binary arrays.
Current section
Files
Jump to
Current section
Files
c_src/float_math.c
#include "erl_nif.h"
#include "mmath.h"
inline ffloat
float_mulc(ffloat v, double m) {
return (ffloat){
.value = v.value * m,
.confidence = v.confidence
};
}
inline ffloat
float_divc(ffloat v, double m) {
return (ffloat){
.value = v.value / m,
.confidence = v.confidence
};
}
inline ffloat
float_addc(ffloat v, double m) {
return (ffloat){
.value = v.value + m,
.confidence = v.confidence
};
}
inline ffloat
float_subc(ffloat v, double m) {
return (ffloat){
.value = v.value - m,
.confidence = v.confidence
};
}
ffloat
float_mul(ffloat a, ffloat b) {
return (ffloat){
.value = a.value * b.value,
.confidence = (a.confidence + b.confidence) / 2
};
}
ffloat
float_mul3(ffloat a, ffloat b, ffloat c) {
return (ffloat){
.value = a.value * b.value * c.value,
.confidence = (a.confidence + b.confidence + c.confidence) / 3
};
}
ffloat
float_div(ffloat a, ffloat b) {
double q = b.value;
if (q == 0) {
q = 1;
}
return (ffloat){
.value = a.value / q,
.confidence = (a.confidence + b.confidence) / 2
};
}
ffloat
float_div3(ffloat a, ffloat b, ffloat c) {
double q1 = b.value;
double q2 = c.value;
if (q1 == 0) {
q1 = 1;
}
if (q2 == 0) {
q2 = 1;
}
return (ffloat){
.value = a.value / q1 / q2,
.confidence = (a.confidence + b.confidence + c.confidence) / 3
};
}
inline ffloat
float_add(ffloat a, ffloat b) {
double confidence = (a.confidence + b.confidence) / 2;
return (ffloat) {
.value = a.value + b.value,
.confidence = confidence
};
}
inline ffloat
float_add3(ffloat a, ffloat b, ffloat c) {
double confidence = (a.confidence + b.confidence + a.confidence) / 3;
return (ffloat) {
.value = a.value + b.value + c.value,
.confidence = confidence
};
}
inline ffloat /* a - b */
float_sub(ffloat a, ffloat b) {
double confidence = (a.confidence + b.confidence) / 2;
return (ffloat) {
.value = a.value - b.value,
.confidence = confidence
};
}
inline ffloat /* a - b */
float_sub3(ffloat a, ffloat b, ffloat c) {
double confidence = (a.confidence + b.confidence + c.confidence) / 3;
return (ffloat) {
.value = a.value - b.value - c.value,
.confidence = confidence
};
}
inline ffloat
float_neg(ffloat a) {
return (ffloat) {
.value = -a.value,
.confidence = a.confidence
};
}
ffloat float_min(ffloat a, ffloat b) {
/* if (b.confidence == 0) { */
/* return a; */
/* } */
/* if (a.confidence == 0) { */
/* return b; */
/* } */
if (b.value < a.value) {
return b;
} else {
return a;
}
}
ffloat float_min3(ffloat a, ffloat b, ffloat c) {
return float_min(a, float_min(b, c));
}
ffloat float_max(ffloat a, ffloat b) {
/* if (b.confidence == 0) { */
/* return a; */
/* } */
/* if (a.confidence == 0) { */
/* return b; */
/* } */
if (b.value > a.value) {
return b;
} else {
return a;
}
}
ffloat float_max3(ffloat a, ffloat b, ffloat c) {
return float_max(a, float_max(b, c));
}