vrld avatar vrld committed 8c72f66

Rename Math.{cpp,h} to ModMath.{cpp,h}.

Compilers can get confused and include Math.h and math.h (included by cmath).

Comments (0)

Files changed (5)

src/modules/math/Math.cpp

-/**
- * Copyright (c) 2006-2013 LOVE Development Team
- *
- * This software is provided 'as-is', without any express or implied
- * warranty.  In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- *    claim that you wrote the original software. If you use this software
- *    in a product, an acknowledgment in the product documentation would be
- *    appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- *    misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- **/
-
-#include "Math.h"
-#include "common/math.h"
-
-#include <cmath>
-
-namespace love
-{
-namespace math
-{
-
-// 64 bit Xorshift implementation taken from the end of Sec. 3 (page 4) in
-// George Marsaglia, "Xorshift RNGs", Journal of Statistical Software, Vol.8 (Issue 14), 2003
-Math::Math()
-{
-	RNGState.seed = 0x0139408DCBBF7A44;
-	RNGState.last_randnormal = std::numeric_limits<double>::infinity();
-}
-
-uint32_t Math::rand()
-{
-	uint64_t &x = RNGState.seed;
-	x ^= (x << 13);
-	x ^= (x >> 7);
-	x ^= (x << 17);
-	return x;
-}
-
-// Box–Muller transform
-double Math::randnormal(double stddev)
-{
-	if (RNGState.last_randnormal != std::numeric_limits<double>::infinity())
-	{
-		double r = RNGState.last_randnormal;
-		RNGState.last_randnormal = std::numeric_limits<double>::infinity();
-		return r * stddev;
-	}
-
-	double r   = sqrt(-2.0 * log(1. - random()));
-	double phi = 2.0 * LOVE_M_PI * (1. - random());
-
-	RNGState.last_randnormal = r * cos(phi);
-	return r * sin(phi) * stddev;
-}
-
-} // math
-} // love

src/modules/math/Math.h

-/**
- * Copyright (c) 2006-2013 LOVE Development Team
- *
- * This software is provided 'as-is', without any express or implied
- * warranty.  In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- *    claim that you wrote the original software. If you use this software
- *    in a product, an acknowledgment in the product documentation would be
- *    appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- *    misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- **/
-
-#ifndef LOVE_MATH_MATH_H
-#define LOVE_MATH_MATH_H
-
-// LOVE
-#include "common/Module.h"
-
-// STL
-#include <limits>
-#include <stdint.h>
-
-namespace love
-{
-namespace math
-{
-
-class Math : public Module
-{
-public:
-	Math();
-	virtual ~Math() {}
-
-	/** Set pseudo random seed.
-	 *
-	 * It's up to the implementation how to use this.
-	 *
-	 * @param seed The random seed.
-	 */
-	inline void randomseed(uint64_t seed)
-	{
-		RNGState.seed = seed;
-	}
-
-	/** Return uniformly distributed pseudo random integer.
-	 *
-	 * @returns Pseudo random integer in [0,2^32).
-	 */
-	uint32_t rand();
-
-	/** Get uniformly distributed pseudo random number in [0,1).
-	 *
-	 * @returns Pseudo random number in [0,1).
-	 */
-	inline double random()
-	{
-		return double(rand()) / (double(std::numeric_limits<uint32_t>::max()) + 1.0);
-	}
-
-	/** Get normally distributed pseudo random number.
-	 *
-	 * @param stddev Standard deviation of the distribution.
-	 * @returns Normally distributed random number with mean 0 and variance (stddev)².
-	 */
-	double randnormal(double stddev);
-
-	virtual const char *getName() const
-	{
-		return "love.math";
-	}
-
-private:
-	struct
-	{
-		uint64_t seed;
-		double last_randnormal;
-	} RNGState;
-};
-
-} // math
-} // love
-
-#endif

src/modules/math/ModMath.cpp

+/**
+ * Copyright (c) 2006-2013 LOVE Development Team
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.  In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ *    claim that you wrote the original software. If you use this software
+ *    in a product, an acknowledgment in the product documentation would be
+ *    appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ *    misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ **/
+
+#include "ModMath.h"
+#include "common/math.h"
+
+#include <cmath>
+
+namespace love
+{
+namespace math
+{
+
+// 64 bit Xorshift implementation taken from the end of Sec. 3 (page 4) in
+// George Marsaglia, "Xorshift RNGs", Journal of Statistical Software, Vol.8 (Issue 14), 2003
+ModMath::ModMath()
+{
+	RNGState.seed = 0x0139408DCBBF7A44;
+	RNGState.last_randnormal = std::numeric_limits<double>::infinity();
+}
+
+uint32_t ModMath::rand()
+{
+	uint64_t &x = RNGState.seed;
+	x ^= (x << 13);
+	x ^= (x >> 7);
+	x ^= (x << 17);
+	return x;
+}
+
+// Box–Muller transform
+double ModMath::randnormal(double stddev)
+{
+	if (RNGState.last_randnormal != std::numeric_limits<double>::infinity())
+	{
+		double r = RNGState.last_randnormal;
+		RNGState.last_randnormal = std::numeric_limits<double>::infinity();
+		return r * stddev;
+	}
+
+	double r   = sqrt(-2.0 * log(1. - random()));
+	double phi = 2.0 * LOVE_M_PI * (1. - random());
+
+	RNGState.last_randnormal = r * cos(phi);
+	return r * sin(phi) * stddev;
+}
+
+} // math
+} // love

src/modules/math/ModMath.h

+/**
+ * Copyright (c) 2006-2013 LOVE Development Team
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.  In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ *    claim that you wrote the original software. If you use this software
+ *    in a product, an acknowledgment in the product documentation would be
+ *    appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ *    misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ **/
+
+#ifndef LOVE_MATH_MODMATH_H
+#define LOVE_MATH_MODMATH_H
+
+// LOVE
+#include "common/Module.h"
+
+// STL
+#include <limits>
+#include <stdint.h>
+
+namespace love
+{
+namespace math
+{
+
+class ModMath : public Module
+{
+public:
+	ModMath();
+	virtual ~ModMath() {}
+
+	/** Set pseudo random seed.
+	 *
+	 * It's up to the implementation how to use this.
+	 *
+	 * @param seed The random seed.
+	 */
+	inline void randomseed(uint64_t seed)
+	{
+		RNGState.seed = seed;
+	}
+
+	/** Return uniformly distributed pseudo random integer.
+	 *
+	 * @returns Pseudo random integer in [0,2^32).
+	 */
+	uint32_t rand();
+
+	/** Get uniformly distributed pseudo random number in [0,1).
+	 *
+	 * @returns Pseudo random number in [0,1).
+	 */
+	inline double random()
+	{
+		return double(rand()) / (double(std::numeric_limits<uint32_t>::max()) + 1.0);
+	}
+
+	/** Get normally distributed pseudo random number.
+	 *
+	 * @param stddev Standard deviation of the distribution.
+	 * @returns Normally distributed random number with mean 0 and variance (stddev)².
+	 */
+	double randnormal(double stddev);
+
+	virtual const char *getName() const
+	{
+		return "love.math";
+	}
+
+private:
+	struct
+	{
+		uint64_t seed;
+		double last_randnormal;
+	} RNGState;
+};
+
+} // math
+} // love
+
+#endif

src/modules/math/wrap_Math.cpp

  **/
 
 #include "wrap_Math.h"
-#include "Math.h"
+#include "ModMath.h"
 
 #include <cmath>
 #include <iostream>
 namespace math
 {
 
-static Math *instance = 0;
+static ModMath *instance = 0;
 
 int w_randomseed(lua_State *L)
 {
 extern "C" int luaopen_love_math(lua_State *L)
 {
 	if (instance == 0)
-		instance = new love::math::Math();
+		instance = new love::math::ModMath();
 	else
 		instance->retain();
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.