Debian Codegraph @

melder/melder_real.h

raw symbols SCIP
1 #cxx . . $ `<file>/melder/melder_real.h`/ifndef _melder_real_h_
2 #define _melder_real_h_cxx . . $ `melder/melder_real.h:2:9`!
3 /* melder_real.h
4 *
5 * Copyright (C) 1992-2021,2023-2025 Paul Boersma
6 *
7 * This code is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or (at
10 * your option) any later version.
11 *
12 * This code is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 * See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this work. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 /*
22 The following is checked in praat.h.
23
24 Ideally, "long double" is 80 bits ("extended") precision (but stored in 96 or 128 bits), or even really 96 or 128 bits.
25 And ideally, long doubles should be fast.
26
27 They *are* fast on Intel64 processors, which have hardware support for them.
28 But they are *very* slow (i.e. software-emulated) on ARM64 processors, which is why Xcode on the Mac and Clang on Windows
29 typically regard a "long double" as being 64 bits, i.e. identical to a "double".
30 On ARM64 Linux, Gcc regards "long double" as 128 bits, but this is very slow (more than 100 times slower than "double"),
31 so we give up and define "longdouble" as "double" on ARM64 Linux, just as was already the case on ARM64 Windows and ARM64 Mac.
32
33 The condition could therefore be
34 #if defined (linux) && (defined (__aarch64__) || defined (_M_ARM64_))
35 but just to make sure that no other Windows or Mac compilers happen to do 128-bit long double emulation,
36 we include Windows and Mac into our condition:
37 */
38 #if defined (__aarch64__) || defined (_M_ARM64_)
39 using longdouble = double;
40 #else
41 using longdoublecxx . . $ longdouble# = long double;
42 #endif
43
44 static const double undefinedcxx . . $ undefined. = (0.0/0.0); // NaN
45
46 /*
47 isdefined() shall capture not only `undefined`, but all infinities and NaNs.
48 This can be done with a single test for the set bits in 0x7FF0'0000'0000'0000,
49 at least for 64-bit IEEE implementations. The correctness of this assumption is checked in sys/praat.cpp.
50 The portable version of isdefined() involves both isinf() and isnan(), or perhaps just isfinite(),
51 but that would be slower (as tested in fon/Praat_tests.cpp)
52 and it would also run into problems on some platforms when both <cmath> and <math.h> are included,
53 as in dwsys/NUMcomplex.cpp.
54 */
55 //inline bool isdefined (double x) { return ! isinf (x) && ! isnan (x); } /* portable */
56 //inline bool isdefined (double x) { return isfinite (x); } /* portable */
57 inline bool isdefinedcxx . . $ isdefined(f8197d536af80c96). (double x) { return ((* (uint64cxx . . $ uint64# *) & x) & 0x7FF0'0000'0000'0000) != 0x7FF0'0000'0000'0000; }
58 inline bool isundefcxx . . $ isundef(f8197d536af80c96). (double x) { return ((* (uint64cxx . . $ uint64# *) & x) & 0x7FF0'0000'0000'0000) == 0x7FF0'0000'0000'0000; }
59
60 template <typename T>
61 constexpr T sqrcxx . . $ sqr(ada6a8422704cf8a). (T x) {
62 return x * x;
63 }
64
65 struct MelderPointcxx . . $ MelderPoint# {
66 double xcxx . . $ MelderPoint#x. = undefinedcxx . . $ undefined., ycxx . . $ MelderPoint#y. = undefinedcxx . . $ undefined.;
67 };
68
69 struct MelderRealRangecxx . . $ MelderRealRange# {
70 double mincxx . . $ MelderRealRange#min. = undefinedcxx . . $ undefined., maxcxx . . $ MelderRealRange#max. = undefinedcxx . . $ undefined.;
71 bool isundefcxx . . $ MelderRealRange#isundef(50ce9a9e25b4a850). () const { return ::isundefcxx . . $ isundef(f8197d536af80c96). (mincxx . . $ MelderRealRange#min.) || ::isundefcxx . . $ isundef(f8197d536af80c96). (maxcxx . . $ MelderRealRange#max.); }
72 bool isEmptycxx . . $ MelderRealRange#isEmpty(50ce9a9e25b4a850). () const { return ! (maxcxx . . $ MelderRealRange#max. > mincxx . . $ MelderRealRange#min.); } // note edge case: will return true if min or max is NaN
73 //double size () {
74 // const double result = max - min;
75 // return std::max (result, 0.0);
76 //}
77 };
78
79 inline bool isundefcxx . . $ isundef(dfa1b40f738f9ef2). (const MelderRealRangecxx . . $ MelderRealRange# me) {
80 return isundefcxx . . $ isundef(f8197d536af80c96). (me.mincxx . . $ MelderRealRange#min.) || isundefcxx . . $ isundef(f8197d536af80c96). (me.maxcxx . . $ MelderRealRange#max.);
81 }
82
83 struct MelderExtremaWithInitcxx . . $ MelderExtremaWithInit# {
84 double mincxx . . $ MelderExtremaWithInit#min. = stdcxx . . $ std/::numeric_limitscxx . . $ std/numeric_limits#<double>::maxcxx . . $ std/numeric_limits#max(e4aa362e81f92a46).();
85 double maxcxx . . $ MelderExtremaWithInit#max. = stdcxx . . $ std/::numeric_limitscxx . . $ std/numeric_limits#<double>::lowestcxx . . $ std/numeric_limits#lowest(e4aa362e81f92a46).();
86 void updatecxx . . $ MelderExtremaWithInit#update(ba8836b59fb42830). (const double val) {
87 if (val < mincxx . . $ MelderExtremaWithInit#min.)
88 mincxx . . $ MelderExtremaWithInit#min. = val;
89 if (val > maxcxx . . $ MelderExtremaWithInit#max.)
90 maxcxx . . $ MelderExtremaWithInit#max. = val;
91 }
92 bool isValidcxx . . $ MelderExtremaWithInit#isValid(50ce9a9e25b4a850). () const {
93 return mincxx . . $ MelderExtremaWithInit#min. <= maxcxx . . $ MelderExtremaWithInit#max.;
94 }
95 };
96
97 struct MelderGaussianStatscxx . . $ MelderGaussianStats# {
98 double meancxx . . $ MelderGaussianStats#mean. = undefinedcxx . . $ undefined., stdevcxx . . $ MelderGaussianStats#stdev. = undefinedcxx . . $ undefined.;
99 };
100
101 struct MelderFractioncxx . . $ MelderFraction# {
102 double numeratorcxx . . $ MelderFraction#numerator. = 0.0, denominatorcxx . . $ MelderFraction#denominator. = 0.0;
103 double getcxx . . $ MelderFraction#get(21b6c25e127938e2). () const {
104 return ourcxx . . $ `melder/melder.h:42:9`! denominatorcxx . . $ MelderFraction#denominator. == 0.0 ? undefinedcxx . . $ undefined. : ourcxx . . $ `melder/melder.h:42:9`! numeratorcxx . . $ MelderFraction#numerator. / ourcxx . . $ `melder/melder.h:42:9`! denominatorcxx . . $ MelderFraction#denominator.;
105 }
106 bool isValidcxx . . $ MelderFraction#isValid(50ce9a9e25b4a850). () const {
107 return ourcxx . . $ `melder/melder.h:42:9`! denominatorcxx . . $ MelderFraction#denominator. != 0.0;
108 }
109 };
110
111 struct MelderCountAndFractioncxx . . $ MelderCountAndFraction# {
112 integercxx . . $ integer# countcxx . . $ MelderCountAndFraction#count. = 0;
113 double numeratorcxx . . $ MelderCountAndFraction#numerator. = 0.0, denominatorcxx . . $ MelderCountAndFraction#denominator. = 0.0;
114 double getFractioncxx . . $ MelderCountAndFraction#getFraction(21b6c25e127938e2). () const {
115 return ourcxx . . $ `melder/melder.h:42:9`! denominatorcxx . . $ MelderCountAndFraction#denominator. == 0.0 ? undefinedcxx . . $ undefined. : ourcxx . . $ `melder/melder.h:42:9`! numeratorcxx . . $ MelderCountAndFraction#numerator. / ourcxx . . $ `melder/melder.h:42:9`! denominatorcxx . . $ MelderCountAndFraction#denominator.;
116 }
117 bool isValidcxx . . $ MelderCountAndFraction#isValid(50ce9a9e25b4a850). () const {
118 return ourcxx . . $ `melder/melder.h:42:9`! denominatorcxx . . $ MelderCountAndFraction#denominator. != 0.0;
119 }
120 };
121
122 /* End of file melder_real.h */
123 #endif