[Pythonmac-SIG] Numeric Q: How to get DBL_MAX, etc. in Python?

Louis M. Pecora pecora@anvil.nrl.navy.mil
Thu, 25 Jul 2002 12:53:36 -0400


--============_-1184506472==_ma============
Content-Type: text/plain; charset="us-ascii" ; format="flowed"

>"Louis M. Pecora" <pecora@anvil.nrl.navy.mil> writes:
>
>>  In C there are platform-specfic, floating-point constants as 
>>follows defined in float.h,
>>
>>  /* The largest double precision # */
>>  DBL_MAX                 (* (double *) __double_max)
>>
>>  /* The accuracy of double precision */
>>  #define DBL_EPSILON     (* (double *) __double_epsilon)
>>
>>  /* The smallest double precision # */
>>  #define DBL_MIN         (* (double *) __double_min)
>>
>>  Where do these reside in Python? 
>
>Nowhere.
>
>>  I have looked over my Python manuals and done a Google search, but
>>  can't find any reference to them or float/double limits outside of
>>  some threads online that are requesting the same as me, but no
>>  answers.  Are there standard Python functions or globals that return
>>  these values for the platform one is operating on?
>
>Nope.  Obviously writing a C extension to expose these shouldn't be
>too hard... (although making them constants is inevitably a bit broken
>-- DBL_EPSILON varies as the rounding mode does, for example).
>
>>  Any help appreciated. Thanks.
>
>Well, not sure this counts.
>
>Cheers,
>M.


Actually, someone online pointed me to the module that did what I 
needed: kinds.py in numeric, viz.,

import kinds

kinds.default_float_kind.
kinds.default_float_kind.DIG
kinds.default_float_kind.EPSILON
kinds.default_float_kind.MAX
kinds.default_float_kind.MAX_10_EXP
kinds.default_float_kind.MAX_EXP
kinds.default_float_kind.MIN
kinds.default_float_kind.MIN_10_EXP
kinds.default_float_kind.MIN_EXP
kinds.default_float_kind.RADIX
kinds.default_float_kind.ROUNDS
kinds.default_float_kind._basic_del
kinds.default_float_kind._basic_get
kinds.default_float_kind._basic_set
kinds.default_float_kind._delete_disallowed
kinds.default_float_kind._properties_d
kinds.default_float_kind._properties_g
kinds.default_float_kind._properties_s
kinds.default_float_kind._write_disallowed
kinds.default_float_kind.get_property_d
kinds.default_float_kind.get_property_g
kinds.default_float_kind.get_property_s
kinds.default_float_kind.is_internal_attribute
kinds.default_float_kind.name
kinds.default_float_kind.set_property
kinds.default_float_kind.str
kinds.default_float_kind.typecode

I'd love to know what other neat modules I don't know about (without 
getting too Zen there).


-- 

Cheers,

Lou Pecora

--============_-1184506472==_ma============
Content-Type: text/html; charset="us-ascii"

<!doctype html public "-//W3C//DTD W3 HTML//EN">
<html><head><style type="text/css"><!--
blockquote, dl, ul, ol, li { margin-top: 0 ; margin-bottom: 0 }
 --></style><title>Re: [Pythonmac-SIG] Numeric Q:  How to get DBL_MAX,
et</title></head><body>
<blockquote type="cite" cite>&quot;Louis M. Pecora&quot;
&lt;pecora@anvil.nrl.navy.mil&gt; writes:<br>
<br>
&gt; In C there are platform-specfic, floating-point constants as
follows defined in float.h,<br>
&gt;<br>
&gt; /* The largest double precision # */<br>
&gt;
DBL_MAX&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span
></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (* (double *)
__double_max)<br>
&gt;<br>
&gt; /* The accuracy of double precision */<br>
&gt; #define DBL_EPSILON&nbsp;&nbsp;&nbsp;&nbsp; (* (double *)
__double_epsilon)<br>
&gt;<br>
&gt; /* The smallest double precision # */<br>
&gt; #define DBL_MIN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
(* (double *) __double_min)<br>
&gt;<br>
&gt; Where do these reside in Python?&nbsp;<br>
<br>
Nowhere.<br>
<br>
&gt; I have looked over my Python manuals and done a Google search,
but<br>
&gt; can't find any reference to them or float/double limits outside
of<br>
&gt; some threads online that are requesting the same as me, but
no<br>
&gt; answers.&nbsp; Are there standard Python functions or globals
that return<br>
&gt; these values for the platform one is operating on?<br>
<br>
Nope.&nbsp; Obviously writing a C extension to expose these shouldn't
be<br>
too hard... (although making them constants is inevitably a bit
broken<br>
-- DBL_EPSILON varies as the rounding mode does, for example).<br>
<br>
&gt; Any help appreciated. Thanks.<br>
<br>
Well, not sure this counts.<br>
</blockquote>
<blockquote type="cite" cite>Cheers,<br>
M.</blockquote>
<div><br></div>
<div><br></div>
<div>Actually, someone online pointed me to the module that did what I
needed: kinds.py in numeric, viz.,</div>
<div><br></div>
<div><font face="Monaco" size="-1" color="#000000">import kinds<br>
<br>
kinds.default_float_kind.<br>
kinds.default_float_kind.DIG<br>
kinds.default_float_kind.EPSILON<br>
kinds.default_float_kind.MAX<br>
kinds.default_float_kind.MAX_10_EXP<br>
kinds.default_float_kind.MAX_EXP<br>
kinds.default_float_kind.MIN<br>
kinds.default_float_kind.MIN_10_EXP<br>
kinds.default_float_kind.MIN_EXP<br>
kinds.default_float_kind.RADIX<br>
kinds.default_float_kind.ROUNDS<br>
kinds.default_float_kind._basic_del<br>
kinds.default_float_kind._basic_get<br>
kinds.default_float_kind._basic_set<br>
kinds.default_float_kind._delete_disallowed<br>
kinds.default_float_kind._properties_d<br>
kinds.default_float_kind._properties_g<br>
kinds.default_float_kind._properties_s<br>
kinds.default_float_kind._write_disallowed<br>
kinds.default_float_kind.get_property_d<br>
kinds.default_float_kind.get_property_g<br>
kinds.default_float_kind.get_property_s<br>
kinds.default_float_kind.is_internal_attribute<br>
kinds.default_float_kind.name<br>
kinds.default_float_kind.set_property<br>
kinds.default_float_kind.str<br>
kinds.default_float_kind.typecode</font><br>
<font face="Monaco" size="-1" color="#000000"></font></div>
<div>I'd love to know what other neat modules I don't know about
(without getting too Zen there).</div>
<div><br></div>
<div><br></div>

<div>-- <br>
<br>
Cheers,<br>
<br>
Lou Pecora<br>
</div>
</body>
</html>
--============_-1184506472==_ma============--