[GRASS-git] [OSGeo/grass] bf7d8b: r.mapcalc: Fix modulo by zero hang and speed up th...

Vaclav Petras noreply at github.com
Wed Oct 7 07:13:24 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/OSGeo/grass
  Commit: bf7d8b6f579d1d3fbbd6da9456325b44e01b3d2f
      https://github.com/OSGeo/grass/commit/bf7d8b6f579d1d3fbbd6da9456325b44e01b3d2f
  Author: Vaclav Petras <wenzeslaus at gmail.com>
  Date:   2026-10-07 (Wed, 07 Oct 2026)

  Changed paths:
    M include/grass/calc.h
    M include/grass/defs/calc.h
    M lib/calc/calc.c
    M lib/calc/xacos.c
    M lib/calc/xasin.c
    M lib/calc/xatan.c
    M lib/calc/xcos.c
    M lib/calc/xdiv.c
    M lib/calc/xexp.c
    M lib/calc/xlog.c
    M lib/calc/xmod.c
    M lib/calc/xpow.c
    M lib/calc/xsin.c
    M lib/calc/xsqrt.c
    M lib/calc/xtan.c
    M raster/r.mapcalc/main.c
    A raster/r.mapcalc/tests/r_mapcalc_math_errors_test.py

  Log Message:
  -----------
  r.mapcalc: Fix modulo by zero hang and speed up threads (#8031)

Check for a zero divisor in the integer modulo, so that 5 % 0 gives
NULL as documented. It hung r.mapcalc on x86 Linux because the SIGFPE
handler returned and the division was executed again.

Remove the SIGFPE handler and the floating_point_exception flags.
Floating point exceptions do not trap by default, so the handler never
ran for floating point operations and the flags never became 1. Still,
every thread reset the shared flag to 0 for every cell, which made the
computation scale poorly with threads. Domain errors still give NaN,
which is NULL, and overflow still gives infinity.

Remove pre_exec(), post_exec(), and the two floating_point_exception
variables from the installed grass/calc.h and from libgrass_calc, so
technically a change to the API. Only r.mapcalc used them, so
practically not an issue.

Test division and modulo by zero, domain errors and infinite input of
the functions which had the flag check, their regular results, and
overflow, all with 1 and 4 threads.

The fix, tests, and benchmarks were prepared with AI assistance (Claude
Code with Opus 5.5).



To unsubscribe from these emails, change your notification settings at https://github.com/OSGeo/grass/settings/notifications


More information about the grass-commit mailing list