What are its smallest and biggest values in python?

See this post.

Relevant parts of the post:

In [2]: import kinds In [3]: kinds.default_float_kind.M kinds.default_float_kind.MAX kinds.default_float_kind.MIN kinds.default_float_kind.MAX_10_EXP kinds.default_float_kind.MIN_10_EXP kinds.default_float_kind.MAX_EXP kinds.default_float_kind.MIN_EXP In [3]: kinds.default_float_kind.MIN Out[3]: 2.2250738585072014e-308

Python uses double-precision floats, which can hold values from about 10 to the -308 to 10 to the 308 power.

http://en.wikipedia.org/wiki/Double%5Fprecision%5Ffloating-point%5Fformat

Try this experiment from the Python prompt:

```
>>> 1e308
1e+308
>>> 1e309
inf
```

10 to the 309 power is an overflow, but 10 to the 38 is not. QED.

Actually, you can probably get numbers smaller than 1e-308 via denormals, but there is a significant performance hit to this. I found that Python is able to handle `1e-324`

but underflows on `1e-325`

and returns `0.0`

as the value.

As a kind of theoretical complement to the previous answers, I would like to mention that the "magic" value ±308 comes directly from the binary representation of floats. Double precision floats are of the form ±c*2**q with a "small" fractional value c (~1), and q an integer written with 11 binary digits (1 bit for its sign). The fact that 2**(2**10-1) has 308 (decimal) digits explains the appearance of 10**±308 in the extreme float values.

Calculation in Python:

```
>>> print len(repr(2**(2**10-1)).rstrip('L'))
308
```

Just playing around; here is an algorithmic method to find the minimum and maximum positive float, hopefully in any python implementation where `float("+inf")`

is acceptable:

```
def find_float_limits():
"""Return a tuple of min, max positive numbers
representable by the platform's float"""
# first, make sure a float's a float
if 1.0/10*10 == 10.0:
raise RuntimeError("Your platform's floats aren't")
minimum= maximum= 1.0
infinity= float("+inf")
# first find minimum
last_minimum= 2*minimum
while last_minimum > minimum > 0:
last_minimum= minimum
minimum*= 0.5
# now find maximum
operands= []
while maximum < infinity:
operands.append(maximum)
try:
maximum*= 2
except OverflowError:
break
last_maximum= maximum= 0
while operands and maximum < infinity:
last_maximum= maximum
maximum+= operands.pop()
return last_minimum, last_maximum
if __name__ == "__main__":
print (find_float_limits()) # python 2 and 3 friendly
```

In my case,

```
$ python so1835787.py
(4.9406564584124654e-324, 1.7976931348623157e+308)
```

so denormals are used.

```
>>> import sys
>>> sys.float_info
sys.floatinfo(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308,
min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53,
epsilon=2.2204460492503131e-16, radix=2, rounds=1)
```

The smallest is `sys.float_info.min`

(2.2250738585072014e-308) and the biggest is `sys.float_info.max`

(1.7976931348623157e+308). See documentation for other properties.

**Update**: you can usually get denormalized minimum as `sys.float_info.min*sys.float_info.epsilon`

. But note, that such numbers are represented with a loss of precision.

Similar Questions

While I was messing around with Python, >>> [attr for attr in dir(1) if not attr.startswith('_')] ['bit_length', 'conjugate', 'denominator', 'imag', 'numerator', 'real'] >>> [attr f

I am trying to truncate some float values contained in the same string but I'm not quite sure how to proceed. Currently I am using the Python xml.dom.minidom to write out some xml using Node.toxml().

I have a binary file which I'm able to open in MATLAB, but unable to open in Python. The binary file is encoded as a 'double float,' thus read by MATLAB with the following line: fread(fopen(fileName)

I am using below query SELECT @local_variable=Adtid from table where Adtid can have multiple values stored into it. As I don't know what to use instead of '=' in @local_variable=Adtid. Can anyone sugg

Can a python module have a __repr__? The idea would be to do something like: import mymodule print mymodule EDIT: precision: I mean a user-defined repr!

What, if anything, is wrong with this line of python code: daterange = [begin + timedelta(n) for n in range((end - begin).days)] Where begin and end are datetime.date objects with valid values. I'm u

I have a list of values for example: G1, G2, G2.5, G3, G4, etc..) How can I check a range of these values in c# say if I wanted to see if value was between G1 and G2.5 ? In Vb.net I can do: Select Ca

Possible Duplicate: Python float - str - float weirdness Python float division does not appear to have accurate results. Can someone explain why? >>>3.0/5 0.59999999999999998

After looking at the various math, float, and decimal functions in Python, I haven't found what I'm looking for. In my program, there may be instances when it will return a float and I need the float

I need to check a variable, called status, of an object in python. What I am doing is the known: if p.status() in range(21,30): where p is my object. I need to check if this status is between -21 an

I'm trying to get the Body Mass Index (BMI) classification for a BMI value that falls within a standard BMI range - for instance, if someone's BMI were 26.2, they'd be in the Overweight range. I mad

I'm trying to debug two different python scripts that execute very similar code. These scripts set a, which is a simple float. For script 1: ipdb> print sys.version 2.7 (r27:82500, Jul 15 2010, 13

I'd like to use argparse on Python 2.7 to require that one of my script's parameters be between the range of 0.0 and 1.0. Does argparse.add_argument() support this?

I would like to map values returned by Python's hash() function to floats in the range 0 to 1. On my system I can do this with scale = 1.0/(2**64) print hash(some_object)*scale+0.5 However, I know th

I want to create a random float array of size 100, with the values in the array ranging from 0 to 1. I have tried random.sample(range(1),100) but that does not work. How can i get what i want to achie

I need a regex to match both, integer values aswell as float numbers (whereas float numbers have a . as seperator). Those numbers are always in a bracket and may have a leading +. What should be v

I need to convert one integer to a float, within a specific range that is ordered in reverse. //if (int) value >= 1 && value <= 16,777,216 //result = convert(value) //if value = 1 //resu

I am not able to return flaot values after calculating average of numbers to output.collect..can anyone please help me?? public static class MapClass extends MapReduceBase implements Mapper { private

What would be the best way to implement a custom range filter using Solr? I.e. I want to show a filter Harddrive (for PC's), which can have a value in the range from 32GB to 2TB. I want these values

I am trying to return the list that function will take in. This is what I have got: def boo_list(my_list): for i in range(0, len(my_list) - 1, 1): print(i) If I call for the function: boo_list([True,

#include <stdio.h> int main() { float a = 0.7; int c; c = a < 0.7; printf(%d, c); } Output printed is 1 though it is printing 0 for all cases except 0.7,7.7 and 0.9, why it is so??? Also i

Instead of making a list of alphabet like this, alpha = ['a','b','c','d'.........'z'] is there any way that we can group it to a range or something? For example, for numbers it can be grouped using r

In my app Admin can enter a rating for each user. Im using raty js to show and also to input the star rating.. Thing is I can get an integer value through this. IM trying to set float values through t

I want to know is there a way to select a range of files using python range command, actually I'm running modeler 9.11 for protein homology modeling? This is the python script: from modeller import *

I need to convert 28 byte value to a 7 float values, each 4 bytes denote 1 float value. I have to implement this in C#. I searched for lot of solutions, but most of them were in C/Java.

I have a textfield of Price. I want only Integer and Float values in it. I have done the Integer. But it is not accepting Float values like : 3110.6 Here is my Code DEMO JS: $(document).ready(function

I have given a zoom range to the graph using zoomRange function through which I can limit the range of zoom in and zoom out. It takes two values which such as zoomRange[min, max] for xaxis and yaxis.

I want to test if two or more values have membership on a list, but I'm getting an unexpected result: >>> 'a','b' in ['b', 'a', 'foo', 'bar'] ('a', True) So, Can Python test the membership o

When filling a grid with color such as when using contourf in pyplot, I need to find a way to change the color that pyplot uses to fill data that exceed the specified range of the colorbar. I wish to

Is there idiomatic and/or elegant Python for zipping and applying a list of functions over a list of values? For example, suppose you have a list of functions: functions = [int, unicode, float, lambda

This question is how to go about selecting multiple rows from a table using a range of values in the WHERE clause. Here is what I am trying to do. I have a commenting application in which you post a c

What I do to generate a random angle is this: float rand_angle = (float)random_.NextDouble() * MathHelper.TwoPi; But I want to generate a random angle from range [a;b], excluding everything in the mi

I have this $number = 0.5 if (is_float($number)) { echo 'float'; } else { echo 'not float'; } and it echos not float. what could be the reason thanks

Can a Hash have duplicate keys or values?

Look at the three lines of code below. float f = 1; float g = 1.1; float h = 1.1f; Second line has compilation errors, while the other lines do not have compilation errors. First line is working fin

Possible Duplicate: Most effective way for float and double comparison I have two values(floats) I am attempting to add together and average. The issue I have is that occasionally these values would

What is the difference between the built in float and numpy.float32? Example a = 58682.7578125 print type(a) print a print type(numpy.float32(a)) print numpy.float32(a) Output: <type 'float'> 5

In PHP, you can do... range(1, 3); // Array(1, 2, 3) range(A, C); // Array(A, B, C) That is, there is a function that lets you get a range of numbers or characters by passing the upper and

This is my formula in python Implement the mathematical function f(x) = -5 x5 + 69 x2 - 47 Define the math function def math_formula(x): # This is the formula math_formula = -5 * (x**5) + 69 *(x**2) -

I would need to have a float variable rounded to 2 significant digits and store the result into a new variable (or the same of before, it doesn't matter) but this is what happens: >>> a 981.3

is there any easy way how to pass float4 or any other vector argument to OpenCL kernel? For scalar argument (int, float) you can pass it directly while calling kernel. For array argument you have to f

This question already has an answer here: What's the purpose of the + (pos) unary operator in Python? 3 answers I am writing a function computing like eval. When I come to float.__pos__ ,I real

I have set of value in float (always less than 0). Which I want to bin into histogram, i,e. each bar in histogram contain range of value [0,0.150) The data I have looks like this: 0.000 0.005 0.124 0.

HI I am getting different results while aggregating float values . The query is given below declare @cy datetime set @d = '12/01/2010' select SUM(total) from ( select sum(amt1) as total from table1 wh

I know this can be done in Ada but I'm new to Java and don't know if I can do this. I would like to make a radian of float subtype from 0 to 2pi. Values outside the range would be considered out of ra

I have a program that takes a float. The number, say, is 1353118103.108893381. The number is part of a larger string that is passed in, with each argument separated by a whitespace. For example Arg1 A

For a vector of named values vec = 1:3, names(vec) = c('x1','x2','x1'), how R deals with different values with the same name? For example vec['x1'] only returns the first value named 'x1'. What if I w

a=range(10) b=a[::-1] print b c=zip(a,b) print c c.sort(key=lambda x:x[1])#is there any other argument print c Is there any other argument except key,for example: value? Thanks.

Can I set a default value of a parameter of a route in angularjs ? Is there a way to have '/products/123' and '/products/' handled by the same route ? I'm looking to refactor my existing code, which l

How can I write float value to file in python so that it can be later read in Java with ObjectInputStream#readFloat? I need high read performance, so I'd like to avoid parsing the float from String.