Skip to content

Commit

Permalink
reformat Base.:^, add @inline, and add _MFV overload
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhang314 committed Sep 26, 2024
1 parent b1f7cef commit 062cc53
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/MultiFloats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1267,14 +1267,6 @@ end

# TODO: MultiFloat-Int arithmetic operators.

function Base.:(^)(x::_MF{T,N}, p::Integer) where {T,N}
if p >= 0
Base.power_by_squaring(x,p)
else
Base.power_by_squaring(inv(x),-p)
end
end

########################################################### ARITHMETIC OVERLOADS


Expand Down Expand Up @@ -1302,6 +1294,12 @@ end
@inline Base.inv(x::_MFV{M,T,N}) where {M,T,N} = one(_MFV{M,T,N}) / x


@inline Base.:^(x::_MF{T,N}, p::Integer) where {T,N} =
signbit(p) ? Base.power_by_squaring(inv(x), -p) : Base.power_by_squaring(x, p)
@inline Base.:^(x::_MFV{M,T,N}, p::Integer) where {M,T,N} =
signbit(p) ? Base.power_by_squaring(inv(x), -p) : Base.power_by_squaring(x, p)


@inline Base.sum(x::_MFV{M,T,N}) where {M,T,N} =
+(ntuple(i -> x[i], Val{M}())...)

Expand Down

0 comments on commit 062cc53

Please sign in to comment.