Skip to content

float() will return 0.0 as a valid value if min is a very small number and max is approaching 0 from the neg. side #203

Open
@conpat

Description

@conpat

Testing some edge cases I came across an unexpected behaviour of float

StreamData.float() will include 0.0 when:

  • negative min and max
  • max approaching 0.0 (but not touching it)
  • min bing a very big negative number.
iex()> StreamData.float(min: -9.9e25, max: -0.1) |> Enum.take(10)
[0.0, -9.9e25, 0.0, -8.6625e25, -2.4749999999999994e25, -6.0328125e25, -9.9e25,
 -1.2374999999999997e25, -1.3921875e25, 0.0]

This should not contain any 0.0

On the other side. These variations work as expected

iex()> StreamData.float(min: -9, max: -0.1) |> Enum.take(10)
[-0.09999999999999964, -9.0, -0.09999999999999964, -0.09999999999999964, -9.0,
 -9.0, -6.21875, -0.09999999999999964, -7.8875, -3.715625]

iex()> StreamData.float(max: -0.1) |> Enum.take(10)
[-0.1, -5.1, -0.1, -0.6625, -1.0375, -0.85, -1.084375, -61.4203125,
 -397.414453125, -21.90859375]

iex()> StreamData.float(min: 0.1, max: 9.9e25) |> Enum.take(10)
[4.95e25, 9.9e25, 6.1874999999999994e25, 9.9e25, 0.1, 5.878125e25, 9.9e25,
 3.673828125e25, 2.475e25, 5.64609375e25]

iex()> StreamData.float(min: 0.1) |> Enum.take(10)
[1.1, 4.1, 0.85, 2.0375, 10.81875, 5.428125, 0.7015625, 0.271875, 384.887109375,
 0.7806640625]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions