-
Notifications
You must be signed in to change notification settings - Fork 153
Open
Description
This can be fixed so:
extension Double {
func isDivisible(by value: Double) -> Bool {
let decimalNumberFormatter = NumberFormatter.init()
decimalNumberFormatter.numberStyle = .decimal
return decimalNumberFormatter.string(from: .init(value: self/value))?.contains(decimalNumberFormatter.decimalSeparator) == false
}
}
func sin(_ value: Double) -> Double {
return value.isDivisible(by: .pi) ? 0 : Foundation.sin(value)
}
func cos(_ value: Double) -> Double {
return (.pi/2+value).isDivisible(by: .pi) ? 0 : Foundation.cos(value)
}
func tan(_ value: Double) -> Double {
return value.isDivisible(by: .pi) ? 0 : (.pi/2+value).isDivisible(by: .pi) ? .infinity : Foundation.tan(value)
}
Metadata
Metadata
Assignees
Labels
No labels