Skip to content

BinaryInteger/power(_:) #53

Description

@oscbyspro

I'll add an exponentiation extension to BinaryInteger. It should wrap around and return an error indicator, making the result equivalent to repeated BinaryInteger/times(_:) calls. Negative and infinite exponents will be banned using Natural<T>.

extension BinaryInteger {

    /// Returns the `power` and `error` of `self` raised to `exponent`.
    ///
    /// ```swift
    /// U8(1).power(Natural(2)) // value: 001, error: false
    /// U8(2).power(Natural(3)) // value: 008, error: false
    /// U8(3).power(Natural(5)) // value: 243, error: false
    /// U8(5).power(Natural(7)) // value: 045, error: true 
    /// U8.exactly(00000078125) // value: 045, error: true
    /// ```
    ///
    /// - Note: Unsigned systems integers are always natural.
    ///
    @inlinable public borrowing func power(_ exponent: borrowing Natural<Self>) -> Fallible<Self> { ... }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions