Reputation: 85
I have Double
data type, cause I need result with floating number, but if my result is negative, it broke all my algorithm. Is there maybe a unsigned data type with floating point?
Upvotes: 5
Views: 5051
Reputation: 726987
Use max
to limit numbers from going below zero:
let posOrZero = max(possiblyNegative, 0)
If possiblyNegative
is above zero, it's going to be the result of max
; Otherwise, zero is returned.
Upvotes: 43