xtan.c 977 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. tan(x)
  8. if floating point exception occurs during the evaluation of tan(x)
  9. the result is NULL
  10. note: x is in degrees.
  11. **********************************************************************/
  12. #define DEGREES_TO_RADIANS (M_PI / 180.0)
  13. int f_tan(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] = tan(arg1[i] * DEGREES_TO_RADIANS);
  32. if (floating_point_exception)
  33. SET_NULL_D(&res[i]);
  34. }
  35. return 0;
  36. }