Hi,
I am using Xcode 9 with Swift 3.2 and I am trying to create a custom function. Here is a snapshot of my code (note the function is actually stolen from your code base):
var evaluator = Evaluator()
let randomX = Function(name: "randomX", evaluator: { state throws -> Double in
var argValues = Array<Double>()
for arg in state.arguments {
let argValue = try state.evaluator.evaluate(arg, substitutions: state.substitutions)
argValues.append(argValue)
}
let lowerBound = argValues.count > 0 ? argValues[0] : Double.leastNormalMagnitude
let upperBound = argValues.count > 1 ? argValues[1] : Double.greatestFiniteMagnitude
let range = upperBound - lowerBound
return (drand48().truncatingRemainder(dividingBy: range)) + lowerBound
})
do {
try evaluator.registerFunction(randomX)
} catch let error {
print (error)
}
let value = try formula.evaluate(using: evaluator, substitutions)
I found my issue, it turns out that having mixed case for a function name was the issue. If I converted all references of "randomX" to "randomx" things worked.
Hi, I am using Xcode 9 with Swift 3.2 and I am trying to create a custom function. Here is a snapshot of my code (note the function is actually stolen from your code base):
But I constantly get the following error:
I looked inside evaluator->functionSet->functionsByName and I see 'randomX' in the list (offset 17).
So I am unsure why MathParser is reporting "unknownFunction("randomX")
Please help!
Jay