PageRenderTime 17ms CodeModel.GetById 9ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/math/common.d

http://github.com/wilkie/djehuty
D | 49 lines | 20 code | 13 blank | 16 comment | 1 complexity | 733cdab48ac76e4dfff19a803e10eee9 MD5 | raw file
 1module math.common;
 2
 3// template the function to accept multiple inputs and outputs
 4// allow the usage of this template, or a general common form
 5
 6// common form: generally returns a double and accepts
 7//		multiple types of inputs
 8
 9import math.mathobject;
10
11import core.definitions;
12
13template _mathFunc(string func) {
14	const char[] _mathFunc = `
15		MathObject ` ~ func ~ `(MathObject operand) {
16			// call corresponding op for the MathObject
17			return operand.op` ~ cast(char)(func[0] - 32) ~ func[1..$] ~ `();
18		}
19
20		`;
21}
22
23mixin(_mathFunc!("sqrt"));
24
25// Abstract standard library (silliness)
26version(Tango) {
27	// Tango
28	public import tango.math.Math;
29
30	// OK. DMD has an issue when you redefine intrinsics...
31	// that is, it forgets they exist.
32	// Eventually, this will cause an error. therefore,
33
34	// XXX: REMOVE when compiler is fixed
35	private import Math = tango.math.Math;
36}
37else {
38	// Phobos
39	public import std.math;
40
41	// OK. DMD has an issue when you redefine intrinsics...
42	// that is, it forgets they exist.
43	// Eventually, this will cause an error. therefore,
44
45	// XXX: REMOVE when compiler is fixed
46	private import Math = std.math;
47}
48
49alias Math.sqrt sqrt;