You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
privateletnumberFormatter=NumberFormatter()privateletdoublePrefixes:Set<String>=Set((0...9).map{"\($0)."}+(0...9).map{"\(-$0)."})publicstructDoubleLiteral:Parser{publicstaticletkind:Kind=.doubleLiteral
publicinit(){}publicvarbody:AnyParser<Double>{Leaf{RegularExpression("-?\\d+(,\\d+)*\\.\\d+(e((-|\\+)?)\\d+)?\\b").map{ match ->Doublein
guard let number = numberFormatter.number(from:String(match.text))else{fatalError()}return number.doubleValue
}}.optimize(using: doublePrefixes)}}
can work with small adjustment
private let numberFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.decimalSeparator = "."
return formatter
}()
But instead of using NSNumberFormatter is it not more performant to just use Double(String(match.text))? Added bonus this always works with decimal separator .
The text was updated successfully, but these errors were encountered:
The code
can work with small adjustment
But instead of using
NSNumberFormatter
is it not more performant to just useDouble(String(match.text))
? Added bonus this always works with decimal separator.
The text was updated successfully, but these errors were encountered: