Questions / Quant development, Numerics & testing
Reject a nonfinite value at the boundary
The guard is only sigma > 0.0. How many of [0.2, nan, inf, −1, 3] does it accept?
Answer it in the app It's free. You get hints, a second try if you miss, and a follow-up question.
Show the answer and worked solution
Answer: 3 values
- nan > 0.0 is False, so NaN is rejected.
- inf > 0.0 is True, so infinity slips through.
- 0.2, inf and 3 pass: 3 values.
Interview shortcut. Accepts 0.2, inf, 3.
Takeaway. isfinite(x) and x > 0 rejects NaN and infinities.
In the app this has a follow-up where one thing about the setup changes. Try the follow-up.