Skip to content

What to do about infinity? #118

Open
@nshaffer

Description

@nshaffer

Sometimes an algorithm needs a way to refer to positive or negative infinity (e.g., integration bounds) or test if a number is infinite. How are we going to do that? I see three directions we could take

  1. Only implement such algorithms for IEEE-compliant real kinds. Use ieee_arithmetic to set and test for infinities.
  2. Define special constants inf_{kind} which is IEEE positive infinity for supported kinds and is a special value (maybe huge(x) + 1.0) for non-IEEE kinds. Likewise, testing for infinities either uses ieee_arithmetic or tests for equality with the defined magic number.
  3. Create a derived type that represents infinity and behaves as much like an IEEE infinity as possible when used alongside reals.

Option 1 is simple but means that some stdlib functionality just can't be implemented for all a compiler's real kinds.

Option 2 is simple for IEEE-compliant kinds but introduces a lot of undefined behavior for non-IEEE kinds. (e.g.: If k is a non-IEEE real kind, we can't guarantee that inf_k - 1.0_k does the "right" thing semantically.)

Option 3 is complicated and might be a pain to use in practice. However, it's the only way I know of to get close to IEEE infinity semantics with non-IEEE reals.

I'd like to hear opinions and alternatives, if people have them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: mathematicslinear algebra, sparse matrices, special functions, FFT, random numbers, statistics, ...

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions