xcos.c 957 B

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