Skip to content

Reduction with & should not widen the type #14897

Closed
@eschnett

Description

@eschnett

This surprised me:

julia> typeof(reduce(&, Int8(0), (Int8(4),)))
Int32

It makes sense of + to widen the type to prevent overflow, but & cannot overflow. I tried to counteract the automatic widening by providing an explicit neutral element, but that didn't help.

I also notice that a + reduction widens Bool to Int64, while a & reduction does not widen it.

Should there be a widereduce in addition to reduce?

Should there be an optional argument T that lets people specify the return type?

Metadata

Metadata

Assignees

No one assigned

    Labels

    collectionsData structures holding multiple items, e.g. setsdesignDesign of APIs or of the language itselfmathsMathematical functions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions