On Fri, Nov 24, 2000 at 08:18:07PM -0600, Jarkko Hietaniemi wrote: > On Fri, Nov 24, 2000 at 09:51:39PM +0000, Nicholas Clark wrote: > > PS I don't like floating point numbers. printf can give you numbers such as > > NaN and Infinity, so why can't scanf read 'em? :-( > > I've been lately adding such intelligence to lexing, e.g. 'Inf' is now > recognized as a number and atof() is applied on it. The problem is nick@Bagpuss [bleadperl-intops]$ perl -wle 'print "infinity" + 1' Argument "infinity" isn't numeric in addition (+) at -e line 1. inf nick@Bagpuss [bleadperl-intops]$ perl -wle 'print "inf" + 1' inf --- sv.c.orig Wed Nov 22 23:58:27 2000 +++ sv.c Sat Nov 25 22:34:57 2000 @@ -2010,6 +2010,7 @@ s++; if (*s != 'I' && *s != 'i') return 0; s++; if (*s != 'T' && *s != 't') return 0; s++; if (*s != 'Y' && *s != 'y') return 0; + s++; } sawinf = 1; } voila: nick@Bagpuss [bleadperl]$ perl -le 'print "infinity" + 1' inf all regression tests still pass no idea where the regression tests for these warnings should go. > that there is no portable way to safely produced NaN and Infs... it > may be that atof() doesn't recognize 'Inf'? (I had a very frustrating Sorry, it was an expression of my general dislike of floating point, following my experience with C & C++ parsing files. And the way that C was happy to output a "number" that it didn't accept as a "number" on input. I'm not suggesting that the C spec is wrong, just that life is frustrating when there's not a round trip (via a file) available for all possible values a float or double holds. Anyway, glibc seems to like NaN and infinity: nick@Bagpuss [bleadperl]$ perl -wle 'print "nan" * 0' Argument "nan" isn't numeric in multiplication (*) at -e line 1. nan nick@Bagpuss [bleadperl]$ perl -wle 'print "control" * 0' Argument "control" isn't numeric in multiplication (*) at -e line 1. 0 FreeBSD doesn't: bash-2.02$ perl -wle 'print "nan" * 0' Argument "nan" isn't numeric in multiply at -e line 1. 0 bash-2.02$ ./perl -wle 'print "inf" + 1' 1 bash-2.02$ ./perl -wle 'print "infinity" + 1' 1 Nicholas ClarkThread Previous | Thread Next