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
2323 -----------------------------------------------------------------------------*/
2424
2525 //-----------------------------------------------------------------------------
26−// name: util_math.c
27−// desc: ...
26+// name: util_math.cpp
27+// desc: a mini-compatibility library for math functions
2828 //
2929 // author: Ge Wang (gewang@cs.princeton.edu)
3030 // Perry R. Cook (prc@cs.princeton.edu)
@@ -36,36 +36,6 @@ · 5 unmodified lines
3636 #include <random>
3737
3838
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−//-----------------------------------------------------------------------------
49−double 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−//-----------------------------------------------------------------------------
60−double trunc( double a )
61−{
62− return (double)(long)a;
63−}
64−#endif // #ifdef __CK_MATH_DEFINE_ROUND_TRUNC
65−
66−
67−
68−#endif
6939
7040
7141 //-----------------------------------------------------------------------------
@@ -104,6 +74,35 @@ void ck_srandom( unsigned s ) { g_ck_global_rng.seed(s); } · 32 unmodified lines
10474
10575
10676
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+
107106 //-----------------------------------------------------------------------------
108107 // name: ck_remainder()
109108 // desc: ...
@@ -120,6 +119,7 @@ double ck_remainder( double a, double b ) · 10 unmodified lines
120119
121120
122121
122+
123123 // the following 6 functions are lifted from PD source
124124 // specifically x_acoustics.c
125125 // http://puredata.info/downloads
@@ -127,6 +127,8 @@ double ck_remainder( double a, double b ) · 1 unmodified line
127127 #define LOGTEN 2.302585092994
128128
129129
130+
131+
130132 //-----------------------------------------------------------------------------
131133 // name: mtof()
132134 // desc: midi to freq
@@ -141,6 +143,8 @@ double mtof( double f ) · 8 unmodified lines
141143 }
142144
143145
146+
147+
144148 //-----------------------------------------------------------------------------
145149 // name: ftom()
146150 // desc: freq to midi
@@ -153,6 +157,8 @@ double ftom( double f ) · 6 unmodified lines
153157 }
154158
155159
160+
161+
156162 //-----------------------------------------------------------------------------
157163 // name: powtodb()
158164 // desc: ...
@@ -168,6 +174,8 @@ double powtodb( double f ) · 9 unmodified lines
168174 }
169175
170176
177+
178+
171179 //-----------------------------------------------------------------------------
172180 // name: rmstodb()
173181 // desc: ...
@@ -183,6 +191,8 @@ double rmstodb( double f ) · 9 unmodified lines
183191 }
184192
185193
194+
195+
186196 //-----------------------------------------------------------------------------
187197 // name: dbtopow()
188198 // desc: ...
@@ -199,6 +209,8 @@ double dbtopow( double f ) · 10 unmodified lines
199209 }
200210
201211
212+
213+
202214 //-----------------------------------------------------------------------------
203215 // name: dbtorms()
204216 // 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