/math/common.d

http://github.com/wilkie/djehuty · D · 49 lines · 20 code · 13 blank · 16 comment · 1 complexity · 733cdab48ac76e4dfff19a803e10eee9 MD5 · raw file

  1. module math.common;
  2. // template the function to accept multiple inputs and outputs
  3. // allow the usage of this template, or a general common form
  4. // common form: generally returns a double and accepts
  5. // multiple types of inputs
  6. import math.mathobject;
  7. import core.definitions;
  8. template _mathFunc(string func) {
  9. const char[] _mathFunc = `
  10. MathObject ` ~ func ~ `(MathObject operand) {
  11. // call corresponding op for the MathObject
  12. return operand.op` ~ cast(char)(func[0] - 32) ~ func[1..$] ~ `();
  13. }
  14. `;
  15. }
  16. mixin(_mathFunc!("sqrt"));
  17. // Abstract standard library (silliness)
  18. version(Tango) {
  19. // Tango
  20. public import tango.math.Math;
  21. // OK. DMD has an issue when you redefine intrinsics...
  22. // that is, it forgets they exist.
  23. // Eventually, this will cause an error. therefore,
  24. // XXX: REMOVE when compiler is fixed
  25. private import Math = tango.math.Math;
  26. }
  27. else {
  28. // Phobos
  29. public import std.math;
  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. // XXX: REMOVE when compiler is fixed
  34. private import Math = std.math;
  35. }
  36. alias Math.sqrt sqrt;