Math.ecl 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*##############################################################################
  2. ## HPCC SYSTEMS software Copyright (C) 2017 HPCC Systems®. All rights reserved.
  3. ############################################################################## */
  4. rtl :=
  5. SERVICE : fold
  6. REAL8 Infinity() : eclrtl,pure,include,library='eclrtl',entrypoint='rtlCreateRealInf';
  7. REAL8 Nan() : eclrtl,pure,include,library='eclrtl',entrypoint='rtlCreateRealNull';
  8. BOOLEAN IsInfinite(REAL8 value) : eclrtl,pure,include,library='eclrtl',entrypoint='rtlIsInfinite';
  9. BOOLEAN IsNaN(REAL8 value) : eclrtl,pure,include,library='eclrtl',entrypoint='rtlIsNaN';
  10. BOOLEAN IsFinite(REAL8 value) : eclrtl,pure,include,library='eclrtl',entrypoint='rtlIsFinite';
  11. REAL8 fmod(REAL8 numer, REAL8 denom, UNSIGNED1 dbz) : eclrtl,pure,include,library='eclrtl',entrypoint='rtlFMod';
  12. BOOLEAN fmatch(REAL8 a, REAL8 b, REAL8 epsilon = 0.0) : eclrtl,pure,include,library='eclrtl',entrypoint='rtlFMatch';
  13. END;
  14. EXPORT Math := MODULE
  15. /**
  16. * Return a real "infinity" value.
  17. *
  18. */
  19. EXPORT REAL8 Infinity := rtl.Infinity();
  20. /**
  21. * Return a non-signalling NaN (Not a Number)value.
  22. *
  23. */
  24. EXPORT REAL8 NaN := rtl.NaN();
  25. /**
  26. * Return whether a real value is infinite (positive or negative).
  27. *
  28. * @param val The value to test.
  29. */
  30. EXPORT BOOLEAN isInfinite(REAL8 val) := rtl.isInfinite(val);
  31. /**
  32. * Return whether a real value is a NaN (not a number) value.
  33. *
  34. * @param val The value to test.
  35. */
  36. EXPORT BOOLEAN isNaN(REAL8 val) := rtl.isNaN(val);
  37. /**
  38. * Return whether a real value is a valid value (neither infinite not NaN).
  39. *
  40. * @param val The value to test.
  41. */
  42. EXPORT BOOLEAN isFinite(REAL8 val) := rtl.isFinite(val);
  43. /**
  44. * Returns the floating-point remainder of numer/denom (rounded towards zero).
  45. * If denom is zero, the result depends on the -fdivideByZero flag:
  46. * 'zero' or unset: return zero.
  47. * 'nan': return a non-signalling NaN value
  48. * 'fail': throw an exception
  49. *
  50. * @param numer The numerator.
  51. * @param denom The denominator.
  52. */
  53. EXPORT REAL8 FMod(REAL8 numer, REAL8 denom) :=
  54. rtl.FMod(numer, denom,
  55. CASE(__DEBUG__('divideByZero'),
  56. 'nan'=>2,
  57. 'fail'=>3,
  58. 1));
  59. /**
  60. * Returns whether two floating point values are the same, within margin of error epsilon.
  61. *
  62. * @param a The first value.
  63. * @param b The second value.
  64. * @param epsilon The allowable margin of error.
  65. */
  66. EXPORT BOOLEAN FMatch(REAL8 a, REAL8 b, REAL8 epsilon=0.0) := rtl.FMatch(a, b, epsilon);
  67. END;