Skip to content

Commit 94c82a0

Browse files
committed
Add Math class with static methods (Math.sin, Math.sqrt etc.)
1 parent 28e8a68 commit 94c82a0

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/Processing.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,6 +2306,29 @@ class NumberWrapperBase {
23062306
String toString() const { return String(::std::to_string(v)); }
23072307
};
23082308

2309+
// Java Math class -- static methods for sketches that use Math.sin() etc.
2310+
class Math {
2311+
public:
2312+
static float abs(float x) { return ::std::abs(x); }
2313+
static float min(float a, float b) { return a<b?a:b; }
2314+
static float max(float a, float b) { return a>b?a:b; }
2315+
static float sqrt(float x) { return ::std::sqrt(x); }
2316+
static float pow(float a, float b) { return ::std::pow(a,b); }
2317+
static float floor(float x) { return ::std::floor(x); }
2318+
static float ceil(float x) { return ::std::ceil(x); }
2319+
static float round(float x) { return ::std::round(x); }
2320+
static float log(float x) { return ::std::log(x); }
2321+
static float exp(float x) { return ::std::exp(x); }
2322+
static float sin(float x) { return ::std::sin(x); }
2323+
static float cos(float x) { return ::std::cos(x); }
2324+
static float tan(float x) { return ::std::tan(x); }
2325+
static float atan2(float y, float x) { return ::std::atan2(y,x); }
2326+
static const float PI;
2327+
static const float E;
2328+
};
2329+
inline const float Math::PI = 3.14159265358979323846f;
2330+
inline const float Math::E = 2.71828182845904523536f;
2331+
23092332
class Integer : public NumberWrapperBase<int> {
23102333
public:
23112334
Integer() : NumberWrapperBase<int>() {}

0 commit comments

Comments
 (0)