On Sun, Jul 5, 2020, 3:51 PM Chris Angelico <rosuav@gmail.com> wrote:
On Mon, Jul 6, 2020 at 2:15 AM David Mertz <mertz@gnosis.cx> wrote:
>
> This is a digression, but does anyone have a nice example IN PYTHON of arriving at a NaN without going through infinity. I think Julia is right and Python is wrong about '0/0', but as things are, that's not an example.
>

Not sure why "without going through infinity" is relevant, but you can always just use float("nan") to get one, and I'm sure there are other calculations that result in nan. It's just that 0/0 (like any other operation that involves division by zero, including 0**-1) immediately raises, rather than silently returning a nan.

Like I said, digression. I teach ieee-754 pretty often, or at least touch on it. I want to demonstrate to students that they might have NaN values to consider.

Constructing one purely artificially with 'float("nan")' doesn't make the point well. Some operation that ends up with overflow infinities that are divided or subtracted is OK. But it would be nice to show a clean example where NANs arise without infinities arising first.