Mantis - Squeak
Viewing Issue Advanced Details
6781 Kernel minor always 11-23-07 22:13 04-18-10 22:04
nicolas cellier  
andreas  
normal  
closed 3.10  
fixed  
none    
none trunk  
0006781: 0.0 raisedTo: -1.0 unexpected result
(0.0 raisedTo: -1) correctly raise a ZeroDivide

while

(0.0 raisedTo: -1.0) ... well, answer 0.0, hem...
 FloatRaisedTo-M6781-nice-test.1.cs [^] (584 bytes) 12-01-07 17:10
 FloatRaisedTo-M6781-nice-patch.1.cs [^] (1,249 bytes) 12-01-07 17:10
 FloatRaisedTo-M6781-nice-patch.2.cs [^] (1,654 bytes) 12-01-07 18:07
 NumberRaisedTo-M6781-nice-test.1.cs [^] (561 bytes) 12-06-07 20:25
 NumberRaisedTo-M6781-nice-patch.1.cs [^] (937 bytes) 12-06-07 20:26
 NumberRaisedTo-M6781-nice-patch.2.cs [^] (987 bytes) 12-06-07 20:41

Notes
(0011453)
nicolas cellier   
11-23-07 22:14   
Sorry Ken, forgot to classify Kernel...
(0011505)
nicolas cellier   
12-01-07 18:06   
Note:

i checked what does C (libm.so.6) in these cases:
pow(negativeZero,zero) -> 1.0
    correct
pow(0.0,0.0) -> 1.0
    questionable could as well answer NaN or raise exception
    possible rationale: pow(-1.0/exp(100.0),0.0) will answer 1.0
    so does pow(+1.0/exp(100.0),0.0) (there is no Float positiveZero)
pow(zero,negativeZero) -> 1.0
    could as well be a division by zero
pow(negativeZero,0.5) -> 0.0
    could as well be NaN (a negative number raised to non integer power)
pow(negativeZero,1.0) -> -0.0
    correct
pow(nan,0.0) -> 1.0
    possibly a bug of libm. Squeak does the same
pow(0.0,nan) -> nan
    Here squeak does answer zero...
pow(0.0,inf) -> 0.0
    questionable could as well be nan
pow(inf,0.0) -> 1.0
    questionable could as well be nan

Note that libm pow seems to also handle raisedToInteger: case...


patch.1.cs does not exactly the same for negativeZero, so I upload patch.2.cs
but this raise a lot of questions when pushing IEEE 754 logic to the borders...
what is really in the standard anyway?


#include <math.h>
#include <stdio.h>

int main() {
        double nz=-1.0/exp(1.0e100);
        double nan=0.0/0.0;
        double inf=exp(100.0);
        printf("1.0/-0.0=%f\n",1.0/nz);
        printf("pow(0.0,0.0)=%f\n",pow(0.0,0.0));
        printf("pow(0.0,-0.0)=%f\n",pow(0.0,nz));
        printf("pow(-0.0,0.0)=%f\n",pow(nz,0.0));
        printf("pow(-0.0,0.5)=%f\n",pow(nz,0.5));
        printf("pow(-0.0,1.0)=%f\n",pow(nz,1.0));
        printf("pow(-1.0,0.5)=%f\n",pow(-1.0,0.5));
        printf("pow(nan,0.0)=%f\n",pow(nan,0.0));
        printf("pow(0.0,nan)=%f\n",pow(0.0,nan));
        printf("pow(0.0,-1.0)=%f\n",pow(0.0,-1.0));
        printf("pow(-0.0,-1.0)=%f\n",pow(nz,-1.0));
        printf("pow(0.0,inf)=%f\n",pow(0.0,inf));
        printf("pow(0.0,-inf)=%f\n",pow(0.0,-inf));
        printf("pow(inf,0.0)=%f\n",pow(inf,0.0));
        printf("pow(-inf,0.0)=%f\n",pow(-inf,0.0));
        return 0;
}

(0011518)
nicolas cellier   
12-06-07 20:45   
Number raisedTo: also has the bug.
Since Float>>#raisedTo: is one of the not-relicenced method (though nothing more than 99% copy-paste from super), the best thing is to simply remove it and arrange for super to return a Float when it has to (using ^self class one).

So pick NumberRaisedTo-M6781-nice-patch.2.cs and forget other patches.
(0011558)
Keith_Hodges   
12-17-07 16:36   
"fix begin"
Installer mantis bug: 6781 fix:'NumberRaisedTo-M6781-nice-patch.2.cs'.
"fix test"
Installer mantis bug: 6781 fix:'NumberRaisedTo-M6781-nice-test.1.cs'.
"fix end"

(0013334)
nicolas cellier   
10-04-09 20:05   
Fixed in http://source.squeak.org/trunk/Kernel-nice.256.mcz [^]