C++
double logarithm(double x, double base=10) {
return log(x) / log(base);
}
CoffeeScript
logarithm = (x, base=10) ->
Math.log(x) / Math.log(base)
Java
double logarithm(double x) {
return logarithm(x, 10);
}
double logarithm(double x, double base) {
return Math.log(x) / Math.log(base);
}
JavaScript
function logarithm(x, base) {
if (base==null) {
base = 10;
}
return Math.log(x) / Math.log(base);
}
Kotlin
fun logarithm(x: Double, base: Double=10.0): Double {
return Math.log(x) / Math.log(base)
}
Lua
function logarithm(x, base)
base = base or 10
return math.log(x) / math.log(base)
end}
Objective-C
해당 기능이 존재하지 않음
Perl
sub logarithm {
my $x = shift;
my $base = shift // 10;
log($x) / log($base);
}
PHP
function logarithm($x, $base=10) {
return log($x) / log($base);
}
Python
def logarithm(x, base=10):
return math.log(x) / math.log(base)
Ruby
def logarithm(x, base=10)
Math.log(x) / Math.log(base)
end
Swift
func logarithm(x: Double, base: Double=10) -> Double {
return log(x) / log(base)
}