xacos.c 996 B

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