Skip to content

tophatsub signals IEEE_DIVIDE_BY_ZERO in src/xray/tophatsub.for #27

Description

@huaxueali

Bug report

I am using Gudrun 2025.1 on Windows. During GudrunX X-ray processing, tophatsub.exe finishes with exit value 0 but prints:

tophatsub> Specify r step size and r maximum [A]:     0.02000   10.00000
tophatsub> Specify Qmax for Lorch window function:    0.05000
  0.981112778             501   0.00000000
Note: The following floating-point exceptions are signalling: IEEE_DIVIDE_BY_ZERO

Reproduction

This can also be reproduced with the bundled XRD example data, for example using examples/XRD/090520d_H2O.soq.

Example command:

tophatsub.exe check.soq 2 1.0 0.05 0.1 0.078074 1.0 0.0 0.02 10.0 0.05 0.0

Suspected cause

The divide-by-zero appears to be in src/xray/tophatsub.for, subroutine tophat3d.

When the first non-zero bin is bin 1, the loop starts with m1=1, so:

m=m1-1
rm=m
rm2=2.0*rm

This makes rm2=0.0, but the code immediately evaluates:

factt=factv/rm2

That triggers IEEE_DIVIDE_BY_ZERO. The value is not actually needed unless the later do l=mmin,mmax loop is entered.

Suggested fix

Move factt=factv/rm2 inside the block where it is needed, and guard against rm2=0.0:

if(mmin.le.mmax.and.rm2.ne.0.0) then
   factt=factv/rm2
   do l=mmin,mmax
      ...
   end do
endif

I tested this locally by recompiling tophatsub.exe; the same reproduction command no longer prints IEEE_DIVIDE_BY_ZERO.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions