xsin.c 1002 B

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