ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/Daodan/MinGW/msys/1.0/share/awk/round.awk
Revision: 1046
Committed: Mon Aug 29 13:19:38 2016 UTC (9 years, 2 months ago) by alloc
File size: 661 byte(s)
Log Message:
Daodan: Added Windows MinGW and build batch file

File Contents

# Content
1 # round.awk --- do normal rounding
2 #
3 # Arnold Robbins, arnold@skeeve.com, Public Domain
4 # August, 1996
5
6 function round(x, ival, aval, fraction)
7 {
8 ival = int(x) # integer part, int() truncates
9
10 # see if fractional part
11 if (ival == x) # no fraction
12 return ival # ensure no decimals
13
14 if (x < 0) {
15 aval = -x # absolute value
16 ival = int(aval)
17 fraction = aval - ival
18 if (fraction >= .5)
19 return int(x) - 1 # -2.5 --> -3
20 else
21 return int(x) # -2.3 --> -2
22 } else {
23 fraction = x - ival
24 if (fraction >= .5)
25 return ival + 1
26 else
27 return ival
28 }
29 }