-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmath_utils.h
More file actions
53 lines (47 loc) · 1.76 KB
/
Copy pathmath_utils.h
File metadata and controls
53 lines (47 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* This file is part of libcxxsupport.
*
* libcxxsupport is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* libcxxsupport is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with libcxxsupport; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* libcxxsupport is being developed at the Max-Planck-Institut fuer Astrophysik
* and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
* (DLR).
*/
/*! \file math_utils.h
* Various convenience mathematical functions.
*
* Copyright (C) 2002-2015 Max-Planck-Society
* \author Martin Reinecke
*/
#ifndef PLANCK_MATH_UTILS_H
#define PLANCK_MATH_UTILS_H
#include <cmath>
#include <vector>
#include <algorithm>
/*! Helper function for linear interpolation (or extrapolation).
The array must be ordered in ascending order; no two values may be equal. */
template<typename T, typename Iter, typename Comp> inline void interpol_helper
(const Iter &begin, const Iter &end, const T &val, Comp comp, tsize &idx,
T &frac)
{
using namespace std;
planck_assert((end-begin)>1,"sequence too small for interpolation");
idx = lower_bound(begin,end,val,comp)-begin;
if (idx>0) --idx;
idx = min(tsize(end-begin-2),idx);
frac = (val-begin[idx])/(begin[idx+1]-begin[idx]);
}
#endif