View on GitHub

Vistle

Distributed Data-parallel Scientific Visualization in VR

math.h
Go to the documentation of this file.
1#ifndef VISTLE_MATH_H
2#define VISTLE_MATH_H
3
4#include <algorithm>
5#include <cmath>
6
7namespace vistle {
8
9template<typename S>
10S clamp(S v, S vmin, S vmax)
11{
12 return std::min(std::max(v, vmin), vmax);
13}
14
15template<typename S, typename Float>
16inline S lerp(S a, S b, Float t)
17{
18 return a + t * (b - a);
19}
20
21template<typename S>
22inline S difference_of_products(S a, S b, S c, S d)
23{
24 S cd = c * d;
25 S err = std::fma(-c, d, cd);
26 S dop = std::fma(a, b, -cd);
27 return dop + err;
28}
29
30} // namespace vistle
31#endif
static T min(T a, T b)
Definition: messages.cpp:28
Definition: allobjects.cpp:30
S lerp(S a, S b, Float t)
Definition: math.h:16
double Float
Definition: scalar.h:18
S difference_of_products(S a, S b, S c, S d)
Definition: math.h:22
S clamp(S v, S vmin, S vmax)
Definition: math.h:10