Re: [pure-lang-users] math.pure
Status: Beta
Brought to you by:
agraef
From: Albert G. <Dr....@t-...> - 2008-08-21 23:41:34
|
Eddie Rucker wrote: > > pow 0 (-1); > <stdin>:2.0-13: unhandled exception 'signal 8' while evaluating 'pow 0 > (-1)' Yeah, that's just 1 div 0 in disguise there, so it's handled the same (see below). Note that GMP's mpz_pow_ui actually raises a SIGFPE in this case. > Did you want to leave this unevaluated or throw an error? > Also, x div 0 throws and error as well? Yes, all integer divisions by zero throw a 'signal SIGFPE' exception now. In previous releases these would just crap out with an unhandled SIGFPE signal generated by the cpu, so this is definitely an improvement. :) In Q, these return a normal form instead, which gives you the opportunity to add your own equations to handle division by zero. But this is not possible in Pure (at least not without sacrificing most of Pure's arithmetic performance), because integer arithmetic compiles to actual machine instructions there. NB: It would be possible to implement this for the bigint operations as these are implemented as calls into the runtime, but I'd rather like these to work consistently with the machine int operations. Also, this is one of the cases where I think it's not really worth the effort, because integer division by 0 almost invariably indicates a serious program bug. Finally, note that you can still define x div 0 any way you want as long as you're doing symbolic calculations (i.e., x is not an integer). > Should we add the following? > > nan^nan = nan; > nan^inf = nan; This already works as of r560. > pow nan nan = nan; > pow nan inf = nan; I'm about to remove the definition of pow on double, it just duplicates the functionality of the ^ operator anyway. Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |