File: __init__.py

package info (click to toggle)
python-application 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 288 kB
  • sloc: python: 1,878; makefile: 2
file content (23 lines) | stat: -rw-r--r-- 595 bytes parent folder | download
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))