Skip to content

Add Bounded instances for Double, Float, CDouble and CFloat #402

@AliceRixte

Description

@AliceRixte

Motivation

Edited TL;DR

Floats can be seen as a representation of extended reals. In that regard, they are bounded between -∞ and +∞. When seeing -1/0 as a representation of -∞ and 1/0 as a representation of +∞, we get a bounded instance for floats.

Initial motivation

Having a Bounded instance for Double is generally useful as soon as one uses 1/0 and -1/0 to represent infinity. For instance , it allows to represent whole intervals (see ekmett/intervals#27 or msakai/data-interval#46)

This was previously discussed here. This Stack Overflow answer suggests the following explanation as to why those instances do not exist :

 >>> let nan = 0/0; infinity = 1/0 in (nan > infinity, infinity > nan)
(False,False)

which means that 1/0 and -1/0 are not actual bounds.

However, the exact same argument can be used to say that there should not even be an Ord instance in a first place, as this means that Double is not totally ordered.

Proposal

Add the following instances to base :

instance Bounded Double where
  minBound = negate (1/0)
  maxBound = 1/0

instance Bounded Float where
  minBound = negate (1/0)
  maxBound = 1/0

as well as the corresponding derived instances for CFloat and CDouble.



Disclaimer

I'm completely new to the CLC process. I'm willing to implement this, but I will probably need guidance, which I would be very grateful for.

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