Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info>:

> There are good ways to deal with out-of-range results in systems
> languages:
>
> - well-defined wrap-around behaviour;
> - saturation;
> - trapping.

Some months back I reported a bug in LXDE's CPU monitor applet: after a
couple of months of operation, the CPU monitor displayed a 100% CPU
utilization rate on an idle machine (on a 32-bit machine).

The reason was that scanf("%ld") saturated at LONG_MAX instead of
wrapping gracefully. Wrapping behavior would have resulted in a
perfectly well-behaved difference (and CPU utilization). As it stood,
saturation destroyed the sane-looking calculation.

The solution was to move to scanf("%lld") and prevent satufation. Again,
I don't blame the code; I blame the spec. Writing a wrapping
implementation of scanf("%ld") is the simplest possible, most obvious
and most obviously correct approach. Only it wouldn't be
standards-compliant.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to