- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.7k
Closed
Labels
mathsMathematical functionsMathematical functionsspeculativeWhether the change will be implemented is speculativeWhether the change will be implemented is speculative
Description
The mathematical expression (-1)^n appears in many equations. It would be convenient to have an efficient standard implementation in Julia. This is, in effect, the inverse of the signbit function.
I propose the following implementation:
function bitsign(b::Bool)::Int
    1 - 2 * b   # this seems to be the most efficient way
end
function bitsign(b::I)::I where {I<:Signed}
    I(bitsign(isodd(b)))
endstevengj and StefanKarpinski
Metadata
Metadata
Assignees
Labels
mathsMathematical functionsMathematical functionsspeculativeWhether the change will be implemented is speculativeWhether the change will be implemented is speculative