xacos.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <stdlib.h>
  2. #include <math.h>
  3. #include <grass/gis.h>
  4. #include <grass/raster.h>
  5. #include "globals.h"
  6. #include "expression.h"
  7. #include "func_proto.h"
  8. /**********************************************************************
  9. acos(x) [0 and PI]
  10. if floating point exception occurs during the evaluation of acos(x)
  11. the result is NULL
  12. note: result is in degrees
  13. **********************************************************************/
  14. #define RADIANS_TO_DEGREES (180.0 / M_PI)
  15. int f_acos(int argc, const int *argt, void **args)
  16. {
  17. DCELL *res = args[0];
  18. DCELL *arg1 = args[1];
  19. int i;
  20. if (argc < 1)
  21. return E_ARG_LO;
  22. if (argc > 1)
  23. return E_ARG_HI;
  24. if (argt[0] != DCELL_TYPE)
  25. return E_RES_TYPE;
  26. if (argt[1] != DCELL_TYPE)
  27. return E_ARG_TYPE;
  28. for (i = 0; i < columns; i++)
  29. if (IS_NULL_D(&arg1[i]))
  30. SET_NULL_D(&res[i]);
  31. else {
  32. floating_point_exception = 0;
  33. res[i] = RADIANS_TO_DEGREES * acos(arg1[i]);
  34. if (floating_point_exception)
  35. SET_NULL_D(&res[i]);
  36. }
  37. return 0;
  38. }