Skip to content

linspace(...)[1] can differ from linspace start value #14420

@c42f

Description

@c42f

Demo:

julia> start = 0.10000000000000045
0.10000000000000045

julia> linspace(start, 1)[1] - start
-1.3877787807814457e-17

julia> linspace(start, 1).start - start
0.0

I think the error here is in unsafe_getindex(::LinSpace, ::Integer), which assumes b*a/b == a, which unfortunately isn't true. The above amounts to computing

julia> 0.10000000000000045 * 49.0 / 49.0 - 0.10000000000000045
-1.3877787807814457e-17

Probably needless to say, this is a big problem for numerical code which should be able to assume LinSpace will exactly preserve the start and end values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviormathsMathematical functions

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions