The value can be != 0, but still small enough to cause overflow result in infinity. And I would not compare floating point values using == in general. I even think that maybeDouble (and other floating point types) should conform to Comparable, but should not to Equatable.
It depends on what you're trying to do. If it's just that your graphics library handles very large finite values but not infinity, then I might do fmin(size.height/cos(angle), SomeVeryLargeFiniteValue) to cap the result (with a corresponding fmax(-SomeVeryLargeFiniteValue) if the value might also be negative).
Division by zero in floating-point is not an error. It simply results in infinity (when dividing a non-zero value by zero) or nan (in the case of 0/0), which are perfectly well-formed floating-point values.
Furthermore, there is no floating-point number x for which cos(x) is zero (the smallest that cos(x) can get in Double is about 1e-19; I would have to look up the exact value). Your x == 0.0 case will never be used.
edit: I checked my notes (KC Ng’s extremely readable note “ARGUMENT REDUCTION FOR HUGE ARGUMENTS: Good to the Last Bit”), the smallest magnitude cosine for Double occurs when
x = ±5319372648326541416707296656673541083813475031793921822105998164685326343987747477646239125204069843392466931105720371047561653378447496736288905533500277726150903890962697774418679535123008556835980236851047840822029788166318932319835828816270258618761216.0
Heh, it occurs to me that I could just choose a number bigger than most screens and be fine. I just struggle with math in the math world, and math in the digital world.
I suspect that you calculate the coordinates incorrectly. When you get those big numbers for x or y, is this really the point where you want to move your path?
My program is a math toy for visualizing the relationship between the trigonometry functions. In this particular case, I’m trying to demonstrate the nature of tangent lines, which approach infinite length near the 90s.
I don’t mind fudging them a little, but I’m hoping for math which works well in a variety of viewing situations, such as 3D ones. If I have to hang on some math safety checks, so be it, but I’m trying to keep it very clean.
Working on this. macOS runs okay in a VM, which is nice. Crashes take 2-3 minutes to recover, which is less good. Especially since I seem to need a lot more code to set up the right conditions.