Robot Framework Integrated Development Environment (RIDE)
frange.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 from .misc import roundup
17 from .robottypes import is_integer, is_string
18 
19 
20 
21 def frange(*args):
22  if all(is_integer(arg) for arg in args):
23  return list(range(*args))
24  start, stop, step = _get_start_stop_step(args)
25  digits = max(_digits(start), _digits(stop), _digits(step))
26  factor = pow(10, digits)
27  return [x/float(factor) for x in range(roundup(start*factor),
28  roundup(stop*factor),
29  roundup(step*factor))]
30 
31 
33  if len(args) == 1:
34  return 0, args[0], 1
35  if len(args) == 2:
36  return args[0], args[1], 1
37  if len(args) == 3:
38  return args
39  raise TypeError('frange expected 1-3 arguments, got %d.' % len(args))
40 
41 
42 def _digits(number):
43  if not is_string(number):
44  number = repr(number)
45  if 'e' in number:
46  return _digits_with_exponent(number)
47  if '.' in number:
48  return _digits_with_fractional(number)
49  return 0
50 
51 
53  mantissa, exponent = number.split('e')
54  mantissa_digits = _digits(mantissa)
55  exponent_digits = int(exponent) * -1
56  return max(mantissa_digits + exponent_digits, 0)
57 
58 
60  fractional = number.split('.')[1]
61  if fractional == '0':
62  return 0
63  return len(fractional)
def _digits_with_fractional(number)
Definition: frange.py:59
def frange(*args)
Like range() but accepts float arguments.
Definition: frange.py:21
def _digits_with_exponent(number)
Definition: frange.py:52
def roundup(number, ndigits=0, return_type=None)
Rounds number to the given number of digits.
Definition: misc.py:34