ph-math/src/main/java/com/helger/numbercruncher/mathutils/BigFunctions.java
public static BigDecimal ln (@Nonnull final BigDecimal x, final int scale)
  {
    // Check that x > 0.
    if (x.signum () <= 0)
    {
      throw new IllegalArgumentException ("x <= 0: " + x);
    }

    // The number of digits to the left of the decimal point.
    final int magnitude = x.toString ().length () - x.scale () - 1;

    if (magnitude < 3)
    {
      return _lnNewton (x, scale);
    }

    // Compute magnitude*ln(x^(1/magnitude)).

    // x^(1/magnitude)
    final BigDecimal root = intRoot (x, magnitude, scale);

    // ln(x^(1/magnitude))
    final BigDecimal lnRoot = _lnNewton (root, scale);

    // magnitude*ln(x^(1/magnitude))
    return BigDecimal.valueOf (magnitude).multiply (lnRoot).setScale (scale, RoundingMode.HALF_EVEN);
  }
public static BigDecimal ln (@Nonnull final BigDecimal x, final int scale)
  {
    // Check that x > 0.
    if (x.signum () <= 0)
    {
      throw new IllegalArgumentException ("x <= 0: " + x);
    }

    // The number of digits to the left of the decimal point.
    final int magnitude = x.toString ().length () - x.scale () - 1;

    if (magnitude < 3)
    {
      return _lnNewton (x, scale);
    }

    // Compute magnitude*ln(x^(1/magnitude)).

    // x^(1/magnitude)
    final BigDecimal root = intRoot (x, magnitude, scale);

    // ln(x^(1/magnitude))
    final BigDecimal lnRoot = _lnNewton (root, scale);

    // magnitude*ln(x^(1/magnitude))
    return BigDecimal.valueOf (magnitude).multiply (lnRoot).setScale (scale, RoundingMode.HALF_EVEN);
  }
public static BigDecimal ln ( @ Nonnull final BigDecimal x , final int scale ) { // Check that x > 0. if ( x . signum ( ) <= 0 ) { throw new IllegalArgumentException ( "x <= 0: " + x ) ; } // The number of digits to the left of the decimal point. final int magnitude = x . toString ( ) . length ( ) - x . scale ( ) - 1 ; if ( magnitude < 3 ) { return _lnNewton ( x , scale ) ; } // Compute magnitude*ln(x^(1/magnitude)). // x^(1/magnitude) final BigDecimal root = intRoot ( x , magnitude , scale ) ; // ln(x^(1/magnitude)) final BigDecimal lnRoot = _lnNewton ( root , scale ) ; // magnitude*ln(x^(1/magnitude)) return BigDecimal . valueOf ( magnitude ) . multiply ( lnRoot ) . setScale ( scale , RoundingMode . HALF_EVEN ) ; }
Compute the natural logarithm of x to a given scale, x &gt; 0.

@param x
Base value
@param scale
Scale
@return ln(x)
Compute the natural logarithm of x to a given scale x &gt ; 0 .