Files
laurent 46a84a64d6 new signature
for the regex now the functions name is :
func captureGroups(from regexPattern: String) -> [String]? {

and fixing some spaces and one typo.

I am sorry, I am quite new to this. Hope I did not change too much at once. Thank you
2021-01-04 19:01:40 +01:00

64 lines
1.5 KiB
Swift

//
// Comparable.swift
// Terminal
//
// Created by Paul Hudson on 20/02/2020.
// Copyright © 2020 Hacking with Swift. All rights reserved.
//
import Foundation
func +<I: BinaryInteger, F: BinaryFloatingPoint>(lhs: I, rhs: F) -> F {
return F(lhs) + rhs
}
func +<I: BinaryInteger, F: BinaryFloatingPoint>(lhs: F, rhs: I) -> F {
return lhs + F(rhs)
}
func -<I: BinaryInteger, F: BinaryFloatingPoint>(lhs: I, rhs: F) -> F {
return F(lhs) - rhs
}
func -<I: BinaryInteger, F: BinaryFloatingPoint>(lhs: F, rhs: I) -> F {
return lhs - F(rhs)
}
func *<I: BinaryInteger, F: BinaryFloatingPoint>(lhs: I, rhs: F) -> F {
return F(lhs) * rhs
}
func *<I: BinaryInteger, F: BinaryFloatingPoint>(lhs: F, rhs: I) -> F {
return lhs * F(rhs)
}
func /<I: BinaryInteger, F: BinaryFloatingPoint>(lhs: I, rhs: F) -> F {
return F(lhs) / rhs
}
func /<I: BinaryInteger, F: BinaryFloatingPoint>(lhs: F, rhs: I) -> F {
return lhs / F(rhs)
}
// ------------------------------------------
// How to replicate the ** operator in Swift
//
infix operator **
func **<I: BinaryInteger>(lhs: I, rhs: I) -> I {
return I(pow(Double(lhs), Double(rhs)))
}
func **<I: BinaryInteger, F: BinaryFloatingPoint>(lhs: I, rhs: F) -> F {
return F(pow(Double(lhs), Double(rhs)))
}
func **<I: BinaryInteger, F: BinaryFloatingPoint>(lhs: F, rhs: I) -> F {
return F(pow(Double(lhs), Double(rhs)))
}
func **<F: BinaryFloatingPoint>(lhs: F, rhs: F) -> F {
return F(pow(Double(lhs), Double(rhs)))
}