@@ -290,6 +290,66 @@ def testLog(self):
290
290
math .log (10 , MyFloat ())
291
291
self .assertRaises (ValueError , math .log , 0 )
292
292
293
+ def testLog1p (self ):
294
+ self .assertRaises (TypeError , math .log1p )
295
+ for n in [2 , 2 ** 90 , 2 ** 300 ]:
296
+ self .assertAlmostEqual (math .log1p (n ), math .log1p (float (n )))
297
+ self .assertRaises (ValueError , math .log1p , - 1 )
298
+ self .assertEqual (math .log1p (INF ), INF )
299
+
300
+ # test of specializations
301
+ self .ftest ('log1p(MyFloat())' , math .log1p (MyFloat ()), 0.4700036292457356 )
302
+ self .assertRaises (TypeError , math .log1p , 'ahoj' )
303
+ self .ftest ('log1p(BIG_INT)' , math .log1p (BIG_INT ), 71.38013712610532 )
304
+
305
+ #@requires_IEEE_754
306
+ def testLog2 (self ):
307
+ self .assertRaises (TypeError , math .log2 )
308
+
309
+ # Check some integer values
310
+ self .assertEqual (math .log2 (1 ), 0.0 )
311
+ self .assertEqual (math .log2 (2 ), 1.0 )
312
+ self .assertEqual (math .log2 (4 ), 2.0 )
313
+
314
+ # Large integer values
315
+ self .assertEqual (math .log2 (2 ** 1023 ), 1023.0 )
316
+ self .assertEqual (math .log2 (2 ** 1024 ), 1024.0 )
317
+ self .assertEqual (math .log2 (2 ** 2000 ), 2000.0 )
318
+
319
+ self .assertRaises (ValueError , math .log2 , - 1.5 )
320
+ self .assertRaises (ValueError , math .log2 , NINF )
321
+ self .assertTrue (math .isnan (math .log2 (NAN )))
322
+
323
+ # test of specializations
324
+ self .ftest ('log2(MyFloat())' , math .log2 (MyFloat ()), - 0.7369655941662062 )
325
+ self .assertRaises (TypeError , math .log2 , 'ahoj' )
326
+ self .ftest ('log2(BIG_INT)' , math .log2 (BIG_INT ), 102.97976984980635 )
327
+
328
+ def testLog2Exact (self ):
329
+ # Check that we get exact equality for log2 of powers of 2.
330
+ actual = [math .log2 (math .ldexp (1.0 , n )) for n in range (- 1074 , 1024 )]
331
+ expected = [float (n ) for n in range (- 1074 , 1024 )]
332
+ self .assertEqual (actual , expected )
333
+
334
+ def testLog10 (self ):
335
+ self .assertRaises (TypeError , math .log10 )
336
+ self .ftest ('log10(0.1)' , math .log10 (0.1 ), - 1 )
337
+ self .ftest ('log10(1)' , math .log10 (1 ), 0 )
338
+ self .ftest ('log10(10)' , math .log10 (10 ), 1 )
339
+ self .ftest ('log10(10**1000)' , math .log10 (10 ** 1000 ), 1000.0 )
340
+ self .assertRaises (ValueError , math .log10 , - 1.5 )
341
+ self .assertRaises (ValueError , math .log10 , - 10 ** 1000 )
342
+ self .assertRaises (ValueError , math .log10 , NINF )
343
+ self .assertEqual (math .log (INF ), INF )
344
+ self .assertTrue (math .isnan (math .log10 (NAN )))
345
+
346
+ # test of specializations
347
+ # TODO uncomment when GR-10346 will be fixed
348
+ #self.ftest('log10(MyFloat())', math.log10(MyFloat()), -0.22184874961635637)
349
+ self .assertRaises (TypeError , math .log10 , 'ahoj' )
350
+ # TODO uncomment when GR-10346 will be fixed
351
+ #self.ftest('log10(BIG_INT)', math.log10(BIG_INT), 30.999999671364986)
352
+
293
353
def testIsfinite (self ):
294
354
self .assertTrue (math .isfinite (0.0 ))
295
355
self .assertTrue (math .isfinite (- 0.0 ))
@@ -952,6 +1012,36 @@ def test_fmod(self):
952
1012
self .assertEqual (math .fmod (2432902008176640000999 , 12.12 ), 10.396369527944033 )
953
1013
self .assertEqual (math .fmod (- 1e-100 , 1e100 ), - 1e-100 )
954
1014
1015
+ def testExp (self ):
1016
+ self .assertRaises (TypeError , math .exp )
1017
+ self .ftest ('exp(-1)' , math .exp (- 1 ), 1 / math .e )
1018
+ self .ftest ('exp(0)' , math .exp (0 ), 1 )
1019
+ self .ftest ('exp(1)' , math .exp (1 ), math .e )
1020
+ self .assertEqual (math .exp (INF ), INF )
1021
+ self .assertEqual (math .exp (NINF ), 0. )
1022
+ self .assertTrue (math .isnan (math .exp (NAN )))
1023
+ self .assertRaises (OverflowError , math .exp , 1000000 )
1024
+
1025
+ # test of specializations
1026
+ self .ftest ('exp(MyFloat())' , math .exp (MyFloat ()), 1.8221188003905089 )
1027
+ self .assertRaises (TypeError , math .exp , 'ahoj' )
1028
+ self .assertRaises (OverflowError , math .exp , BIG_INT )
1029
+
1030
+ def testExpm1 (self ):
1031
+ self .assertRaises (TypeError , math .exp )
1032
+ self .ftest ('expm1(-1)' , math .expm1 (- 1 ), 1 / math .e - 1 )
1033
+ self .ftest ('expm1(0)' , math .expm1 (0 ), 0 )
1034
+ self .ftest ('expm1(1)' , math .expm1 (1 ), math .e - 1 )
1035
+ self .assertEqual (math .expm1 (INF ), INF )
1036
+ self .assertEqual (math .expm1 (NINF ), - 1. )
1037
+ self .assertTrue (math .isnan (math .expm1 (NAN )))
1038
+ self .assertRaises (OverflowError , math .expm1 , 1000000 )
1039
+
1040
+ # test of specializations
1041
+ self .ftest ('expm1(MyFloat())' , math .expm1 (MyFloat ()), 0.8221188003905089 )
1042
+ self .assertRaises (TypeError , math .expm1 , 'ahoj' )
1043
+ self .assertRaises (OverflowError , math .expm1 , BIG_INT )
1044
+
955
1045
def test_frexp (self ):
956
1046
self .assertRaises (TypeError , math .frexp )
957
1047
@@ -970,6 +1060,11 @@ def testfrexp(name, result, expected):
970
1060
self .assertEqual (math .frexp (NINF )[0 ], NINF )
971
1061
self .assertTrue (math .isnan (math .frexp (NAN )[0 ]))
972
1062
1063
+ # test of specializations
1064
+ testfrexp ('frexp(MyFloat())' , math .frexp (MyFloat ()), (0.6 , 0 ))
1065
+ self .assertRaises (TypeError , math .log1p , 'ahoj' )
1066
+ testfrexp ('log1p(BIG_INT)' , math .frexp (BIG_INT ), (0.9860753853527933 , 103 ))
1067
+
973
1068
testfrexp ('frexp(True)' , math .frexp (True ), (0.5 , 1 ))
974
1069
testfrexp ('frexp(False)' , math .frexp (False ), (0.0 , 0 ))
975
1070
testfrexp ('frexp(6227020800)' , math .frexp (6227020800 ), (0.7249206304550171 , 33 ))
@@ -986,6 +1081,8 @@ def getY():
986
1081
987
1082
testfrexp ('frexp(X(10))' , math .frexp (X (10 )), (0.625 , 4 ))
988
1083
testfrexp ('frexp(Y(11.11))' , math .frexp (Y (11.11 )), (0.694375 , 4 ))
1084
+ testfrexp ('frexp(2**1023)' , math .frexp (2 ** 1023 ), (0.5 , 1024 ))
1085
+ self .assertRaises (OverflowError , math .frexp , 2 ** 1024 )
989
1086
990
1087
def test_ldexp (self ):
991
1088
self .assertRaises (TypeError , math .ldexp )
0 commit comments