Skip to content

The _d() function seems to cause an infinite loop for large numbers. #711

@dklong-csu

Description

@dklong-csu

See a minimal working example here.

If I attempt a comparison such as

double a = 1.e19;
expect(a  == _d(1.e19));

then the resulting program hangs. Using 1.e18 instead is no problem. I did not check values in between.

This is compiled with GCC 13.3.0 installed on Ubuntu 24.04.4 LTS via apt.

Compiling with -D CMAKE_BUILD_TYPE=Debug and -D CMAKE_BUILD_TYPE=Release both trigger the bug.

I realize it's a bit strange to perform an equality comparison of two floating points that are fairly large. I encountered this when writing a parser for an input file format used in chemistry communities. The file format is a bit complex and includes physical quantities that can be very large (>1.e20), so it is worth it to check that I read the files correctly. In this case, the read number should be unspoiled by floating point arithmetic errors and so (conceptually) a direct equality check is the appropriate thing to do.

My workaround is to check relative error:

double a = 1.e19;
expect(std::abs(a - 1.e19) / 1.e19 <= _d(1.e-9));

This is acceptable for my use case, but thought I would share the bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions