Mercurial Hosting > traffic-intelligence
changeset 32:48e56179c39e
added ceil function
author | Nicolas Saunier <nico@confins.net> |
---|---|
date | Sat, 10 Apr 2010 18:58:43 -0400 |
parents | c000f37c316d |
children | 4bd7cc69b6cd |
files | python/tests/utils.txt python/utils.py |
diffstat | 2 files changed, 12 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/python/tests/utils.txt Sat Feb 13 19:46:33 2010 -0500 +++ b/python/tests/utils.txt Sat Apr 10 18:58:43 2010 -0400 @@ -8,6 +8,11 @@ >>> computeChi2(range(1,9),range(1,10)) 0.0 +>>> ceilDecimals(1.23, 0) +2.0 +>>> ceilDecimals(1.23, 1) +1.3 + >>> segmentIntersection(Point(0,0),Point(1,1), Point(0,1), Point(1,2)) >>> segmentIntersection(Point(0,1),Point(1,0), Point(0,2), Point(2,1)) >>> segmentIntersection(Point(0,0),Point(2,0), Point(1,-1),Point(1,1))
--- a/python/utils.py Sat Feb 13 19:46:33 2010 -0500 +++ b/python/utils.py Sat Apr 10 18:58:43 2010 -0400 @@ -31,6 +31,13 @@ # maths section ######################### +def ceilDecimals(v, nDecimals): + '''Rounds the number at the nth decimal + eg 1.23 at 0 decimal is 2, at 1 decimal is 1.3''' + from math import ceil,pow + tens = pow(10,nDecimals) + return ceil(v*tens)/tens + def segmentIntersection(p1, p2, p3, p4): '''Returns the intersecting point of the segments [p1, p2] and [p3, p4], None otherwise''' from numpy import matrix