Bc (programming language): Difference between revisions

Content deleted Content added
Only resembling C: rename section
An equivalent "power" function in GNU bc: removed duplicated section as per the talk page
Line 160:
}
return ( e( y * l(x) ) )
}
</syntaxhighlight>
 
=== An equivalent "power" function in GNU bc ===
<syntaxhighlight lang="c">
# A function to return the integer part of a number
define int(number) {
auto oldscale
oldscale = scale
scale = 0
number /= 1 /* round number down */
scale = oldscale
return number
}
# Use the fact that number^exponent == e^(exponent*log(number))
define power(number,exponent) {
if (exponent == int(exponent)) {
return number ^ int(exponent)
} else {
return e( exponent * l(number) )
}
}
</syntaxhighlight>