@@ -47,6 +47,7 @@ public class CmathModuleBuiltins extends PythonBuiltins {
47
47
48
48
static final double largeDouble = Double .MAX_VALUE / 4.0 ; // used to avoid overflow
49
49
static final double ln2 = 0.6931471805599453094 ; // natural log of 2
50
+ static final double ln10 = 2.302585092994045684 ; // natural log of 10
50
51
51
52
@ Override
52
53
protected List <? extends NodeFactory <? extends PythonBuiltinBaseNode >> getNodeFactories () {
@@ -360,6 +361,8 @@ private PComplex rect(double r, double phi) {
360
361
@ GenerateNodeFactory
361
362
abstract static class LogNode extends PythonBinaryBuiltinNode {
362
363
364
+ abstract PComplex executeComplex (VirtualFrame frame , Object x , Object y );
365
+
363
366
// @formatter:off
364
367
@ CompilerDirectives .CompilationFinal (dimensions = 2 )
365
368
private static final ComplexConstant [][] SPECIAL_VALUES = {
@@ -373,6 +376,10 @@ abstract static class LogNode extends PythonBinaryBuiltinNode {
373
376
};
374
377
// @formatter:on
375
378
379
+ static LogNode create () {
380
+ return CmathModuleBuiltinsFactory .LogNodeFactory .create ();
381
+ }
382
+
376
383
@ Specialization (guards = "isNoValue(y)" )
377
384
PComplex doComplexNone (PComplex x , @ SuppressWarnings ("unused" ) PNone y ) {
378
385
return log (x );
@@ -431,6 +438,25 @@ private double computeRealPart(double real, double imag) {
431
438
}
432
439
}
433
440
441
+ @ Builtin (name = "log10" , minNumOfPositionalArgs = 1 )
442
+ @ TypeSystemReference (PythonArithmeticTypes .class )
443
+ @ ImportStatic (MathGuards .class )
444
+ @ GenerateNodeFactory
445
+ abstract static class Log10Node extends PythonUnaryBuiltinNode {
446
+ @ Child LogNode logNode = LogNode .create ();
447
+
448
+ @ Specialization
449
+ PComplex doComplex (VirtualFrame frame , PComplex z ) {
450
+ PComplex r = logNode .executeComplex (frame , z , PNone .NO_VALUE );
451
+ return factory ().createComplex (r .getReal () / ln10 , r .getImag () / ln10 );
452
+ }
453
+
454
+ @ Specialization
455
+ PComplex doGeneral (VirtualFrame frame , Object zObj , @ Cached CoerceToComplexNode coerceXToComplex ) {
456
+ return doComplex (frame , coerceXToComplex .execute (frame , zObj ));
457
+ }
458
+ }
459
+
434
460
@ Builtin (name = "sqrt" , minNumOfPositionalArgs = 1 )
435
461
@ GenerateNodeFactory
436
462
abstract static class SqrtNode extends CmathComplexUnaryBuiltinNode {
0 commit comments