History

tidy up util_math

Ge Wang committed 3 years ago

Commit 5d4d2081 parent f01910c2 files · +45 −33Browse files

Showing the changes to src/core/util_math.cpp (1 of 2 files). Show all

Unified · Split

src/core/util_math.cpp+44−32
@@ -23,8 +23,8 @@ · 22 unmodified lines
23-----------------------------------------------------------------------------*/23-----------------------------------------------------------------------------*/
24 24
25//-----------------------------------------------------------------------------25//-----------------------------------------------------------------------------
26// name: util_math.c26// name: util_math.cpp
27// desc: ...27// desc: a mini-compatibility library for math functions
28//28//
29// author: Ge Wang (gewang@cs.princeton.edu)29// author: Ge Wang (gewang@cs.princeton.edu)
30// Perry R. Cook (prc@cs.princeton.edu)30// Perry R. Cook (prc@cs.princeton.edu)
@@ -36,36 +36,6 @@ · 5 unmodified lines
36#include <random>36#include <random>
37 37
38 38
39// windows / visual c++
40#ifdef __PLATFORM_WIN32__
41
42
43
44#ifdef __CK_MATH_DEFINE_ROUND_TRUNC__
45//-----------------------------------------------------------------------------
46// name: round()
47// desc: ...
48//-----------------------------------------------------------------------------
49double round( double a )
50{
51 if( a >= 0 ) return (double)(t_CKINT)( a + .5 );
52 else return (double)(t_CKINT)( a - .5 );
53}
54
55
56//-----------------------------------------------------------------------------
57// name: trunc()
58// desc: ...
59//-----------------------------------------------------------------------------
60double trunc( double a )
61{
62 return (double)(long)a;
63}
64#endif // #ifdef __CK_MATH_DEFINE_ROUND_TRUNC
65
66
67
68#endif
69 39
70 40
71//-----------------------------------------------------------------------------41//-----------------------------------------------------------------------------
@@ -104,6 +74,35 @@ void ck_srandom( unsigned s ) { g_ck_global_rng.seed(s); } · 32 unmodified lines
104 74
105 75
106 76
77
78// windows / visual c++
79#ifdef __PLATFORM_WIN32__
80#ifdef __CK_MATH_DEFINE_ROUND_TRUNC__
81//-----------------------------------------------------------------------------
82// name: round()
83// desc: ...
84//-----------------------------------------------------------------------------
85 double round(double a)
86 {
87 if (a >= 0) return (double)(t_CKINT)(a + .5);
88 else return (double)(t_CKINT)(a - .5);
89 }
90
91
92 //-----------------------------------------------------------------------------
93 // name: trunc()
94 // desc: ...
95 //-----------------------------------------------------------------------------
96 double trunc(double a)
97 {
98 return (double)(long)a;
99 }
100#endif // __CK_MATH_DEFINE_ROUND_TRUNC
101#endif // __PLATFORM_WIN32__
102
103
104
105
107//-----------------------------------------------------------------------------106//-----------------------------------------------------------------------------
108// name: ck_remainder()107// name: ck_remainder()
109// desc: ...108// desc: ...
@@ -120,6 +119,7 @@ double ck_remainder( double a, double b ) · 10 unmodified lines
120 119
121 120
122 121
122
123// the following 6 functions are lifted from PD source123// the following 6 functions are lifted from PD source
124// specifically x_acoustics.c124// specifically x_acoustics.c
125// http://puredata.info/downloads125// http://puredata.info/downloads
@@ -127,6 +127,8 @@ double ck_remainder( double a, double b ) · 1 unmodified line
127#define LOGTEN 2.302585092994127#define LOGTEN 2.302585092994
128 128
129 129
130
131
130//-----------------------------------------------------------------------------132//-----------------------------------------------------------------------------
131// name: mtof()133// name: mtof()
132// desc: midi to freq134// desc: midi to freq
@@ -141,6 +143,8 @@ double mtof( double f ) · 8 unmodified lines
141}143}
142 144
143 145
146
147
144//-----------------------------------------------------------------------------148//-----------------------------------------------------------------------------
145// name: ftom()149// name: ftom()
146// desc: freq to midi150// desc: freq to midi
@@ -153,6 +157,8 @@ double ftom( double f ) · 6 unmodified lines
153}157}
154 158
155 159
160
161
156//-----------------------------------------------------------------------------162//-----------------------------------------------------------------------------
157// name: powtodb()163// name: powtodb()
158// desc: ...164// desc: ...
@@ -168,6 +174,8 @@ double powtodb( double f ) · 9 unmodified lines
168}174}
169 175
170 176
177
178
171//-----------------------------------------------------------------------------179//-----------------------------------------------------------------------------
172// name: rmstodb()180// name: rmstodb()
173// desc: ...181// desc: ...
@@ -183,6 +191,8 @@ double rmstodb( double f ) · 9 unmodified lines
183}191}
184 192
185 193
194
195
186//-----------------------------------------------------------------------------196//-----------------------------------------------------------------------------
187// name: dbtopow()197// name: dbtopow()
188// desc: ...198// desc: ...
@@ -199,6 +209,8 @@ double dbtopow( double f ) · 10 unmodified lines
199}209}
200 210
201 211
212
213
202//-----------------------------------------------------------------------------214//-----------------------------------------------------------------------------
203// name: dbtorms()215// name: dbtorms()
204// desc: ...216// desc: ...

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t