Merge pull request #3 from multitudes/master

Adding  '**' operator for exponential
This commit is contained in:
Paul Hudson 2020-04-03 20:59:54 +01:00 committed by GitHub
commit 47bac1e184
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -39,3 +39,25 @@ func /<I: BinaryInteger, F: BinaryFloatingPoint>(lhs: I, rhs: F) -> F {
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)))
}

View File

@ -53,6 +53,8 @@ brisk myscriptname
That will create a new directory called `myscriptname`, copy in all the helper functions, then open it in Xcode ready for you to edit. Using Xcode means you get full code completion, and can run your script by pressing Cmd+R like usual.
Using `swift run` from that directory, the script will run from the command line; if you use `swift build` you'll get a finished binary you can put anywhere.
**Warning:** The `brisk` command is easily the most experimental part of this whole package, so please let me know how you get on with it. Ideally it should create open Xcode straight to an editing window saying `print("Hello, Brisk!")`, but let me know if you get something else.