xtan.c 1022 B

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