Skip to content

The product of a range and a unit should create a new range, not a vector #65

Open

Description

The following expression generates a vector:

julia> (1:3)*seconds
3-element Vector{AstroPeriod{AstroTime.Periods.Second, Float64}}:
1.0 seconds
2.0 seconds
3.0 seconds

I argue that it should create a new range:

julia> (1:3)*seconds
1 seconds: 1 seconds: 3 seconds

The reason is that the expression "(1:typemax(Int32))*seconds" is inefficient in terms of time and memory, because it generates a huge vector, instead of a range type.

If you want to generate a vector, then use the dot notation, i.e., "(1:3).*seconds".

This change just requires the addition of two functions, one each for the implied and explicit versions of step.

Also, the expression "(1:typemax(Int64))*seconds" generates an incorrect result, because the maximum value is converted to a float and then back to an integer. This corner case should be handled properly. Int32 works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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