xsqrt.c 890 B

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