-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
58 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// GammaFunc.swift | ||
// | ||
// | ||
// Created by Pedro Ésli Vieira do Nascimento on 19/03/24. | ||
// | ||
|
||
import Darwin | ||
|
||
public struct GammaFunc: FunctionResultHandling { | ||
public static let name: String = "gamma" | ||
|
||
public static func handle(parameters: [CallParameter]) throws -> Value { | ||
guard !parameters.isEmpty else { throw FunctionError.missingArgument(parameter: "x") } | ||
guard parameters.count == 1 else { throw FunctionError.extraArgument } | ||
|
||
let x = parameters[0].value | ||
|
||
guard x.type.isNumber else { throw FunctionError.typeError(parameterType: x.type, expectedType: .number) } | ||
|
||
return Value(float: tgamma(x.asFloat)) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
Sources/PlatoCore/Functions/Native/Math/LogGammaFunc.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// LogGammaFunc.swift | ||
// | ||
// | ||
// Created by Pedro Ésli Vieira do Nascimento on 19/03/24. | ||
// | ||
|
||
import Darwin | ||
|
||
public struct LogGammaFunc: FunctionResultHandling { | ||
public static let name: String = "logGamma" | ||
|
||
public static func handle(parameters: [CallParameter]) throws -> Value { | ||
guard !parameters.isEmpty else { throw FunctionError.missingArgument(parameter: "x") } | ||
guard parameters.count == 1 else { throw FunctionError.extraArgument } | ||
|
||
let x = parameters[0].value | ||
|
||
guard x.type.isNumber else { throw FunctionError.typeError(parameterType: x.type, expectedType: .number) } | ||
return Value(float: lgamma(x.asFloat).0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ final class PlatoTests: XCTestCase { | |
|
||
func testGeneral() { | ||
let code = """ | ||
6 | ||
cos(90) | ||
2 | ||
"321pedro" | ||
""" | ||
|