Garfield++ 3.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
minmax.h
Go to the documentation of this file.
1#ifndef MINMAX_H
2#define MINMAX_H
3/*
4Copyright (c) 2001 Igor Borisovich Smirnov
5
6Permission to use, copy, modify, distribute and sell this file
7and its documentation for any purpose is hereby granted without fee,
8provided that the above copyright notice, this permission notice,
9and notices about any modifications of the original text
10appear in all copies and in supporting documentation.
11This software is distributed in the hope that it will be useful,
12but the author makes no representations about the suitability
13of this software for any particular purpose.
14It is provided "as is" without express or implied warranty.
15*/
16
17#ifdef VISUAL_STUDIO
18#define _USE_MATH_DEFINES
19// see comment in math.h:
20/* Define _USE_MATH_DEFINES before including math.h to expose these macro
21 * definitions for common math constants. These are placed under an #ifdef
22 * since these commonly-defined names are not part of the C/C++ standards.
23 */
24#endif
25#include <cmath>
26#include <cfloat>
28
29namespace Heed {
30
31/// Minimal power of e the result of which can be represented.
32static const double dbl_min_e_exp = (DBL_MIN_EXP - 1) * log(double(FLT_RADIX));
33/// Maximal power of e the result of which can be represented.
34/// Similar numbers for a != e can be obtained in the user's program by
35/// double dbl_max_a_exp = dbl_max_e_exp / log(a);
36static const double dbl_max_e_exp = (DBL_MAX_EXP - 1) * log(double(FLT_RADIX));
37/// Largest number the square of which can be represented.
38static const double dbl_max_square = sqrt(DBL_MAX);
39
40static const double flt_min_e_exp = (FLT_MIN_EXP - 1) * log(double(FLT_RADIX));
41static const double flt_max_e_exp = (FLT_MAX_EXP - 1) * log(double(FLT_RADIX));
42/// Largest number the square of which can be represented.
43static const double flt_max_square = sqrt(FLT_MAX);
44
45inline long left_round(double f) {
46 return f >= 0 ? long(f) : -long(-f) - 1;
47}
48
49template <class T>
50inline T tabs(const T& x) {
51 return x >= 0 ? x : -x;
52}
53
54template <class T>
55int apeq_mant(const T& x1, const T& x2, T prec) {
56 if (x1 == x2) return 1;
57 if (prec == 0) return 0;
58 if (x1 == 0 && x2 == 0) return 1;
59 if ((x1 < 0 && x2 > 0) || (x1 > 0 && x2 < 0)) return 0;
60 if (tabs((x1 - x2) / (x1 + x2)) <= prec) return 1;
61 return 0;
62}
63
64}
65
66#endif
Definition: BGMesh.cpp:6
T tabs(const T &x)
Definition: minmax.h:50
long left_round(double f)
Definition: minmax.h:45
int apeq_mant(const T &x1, const T &x2, T prec)
Definition: minmax.h:55
DoubleAc sqrt(const DoubleAc &f)
Definition: DoubleAc.cpp:314