#!/usr/bin/bc # bc integer functions I've found useful # while systems programming in the unix environment. # License: LGPLv2 # Author: # http://www.pixelbeat.org/ # Notes: # I only use bc when python is not available. # Personally I have this file in ~/bin/bc so # that I can just invoke bc as normal and have these # extra functions available. # Changes: # V0.1, 11 Apr 2007, Initial release define min(x,y) { if (xy) return x return y } define abs(x) { if (x<0) return -x return x } /* take integer part */ define int(x) { auto old_scale /* variables global by default */ old_scale=scale /* scale is global */ scale=0; ret=x/1 scale=old_scale return ret } /* round to nearest integer */ define round(x) { if (x<0) x-=.5 else x+=.5 return int(x) } /* smallest integer >= arg */ define ceil(x) { auto intx intx=int(x) if (intx