1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
# Copyright (C) 2007-2011 Dan Pascu. See LICENSE for details.
#
"""Pyhton language extensions"""
__all__ = ['Null', 'limit']
from application.python.types import NullType
Null = NullType()
try:
negative_infinite = float('-infinity')
positive_infinite = float('infinity')
except ValueError:
negative_infinite = -1e300000
positive_infinite = 1e300000
def limit(value, min=negative_infinite, max=positive_infinite):
"""Limit a numeric value to the specified range"""
from __builtin__ import min as minimum, max as maximum
return maximum(min, minimum(value, max))
|