473,395 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

More int and float attributes

sys.maxint gives the largest positive integer supported by Python's
regular integer type. But maybe such attribute, with few others (they
can be called min and max) can be given to int type itself.
D is a very nice language, that I hope to see more used. It is copying
lot of things from Python. D Floating point values have some
proprieties:

http://www.digitalmars.com/d/property.html

Properties for Floating Point Types:
..init initializer (NaN)
..infinity infinity value
..nan NaN value
..dig number of decimal digits of precision
..epsilon smallest increment
..mant_dig number of bits in mantissa
..max_10_exp maximum exponent as power of 10
..max_exp maximum exponent as power of 2
..min_10_exp minimum exponent as power of 10
..min_exp minimum exponent as power of 2
..max largest representable value that's not infinity
..min smallest representable value that's not 0
..re real part
..im imaginary part

I think such attributes may be useful to be added to Python float
type/values too.

Bye,
bearophile

Aug 5 '06 #1
8 9456
It seems as though just about all of those would be rarely, if ever,
used by the vast majority of programmers.

Plus, python already handles the two most important (NaN and complex)
well.

Aug 5 '06 #2

be************@lycos.com wrote:
sys.maxint gives the largest positive integer supported by Python's
regular integer type. But maybe such attribute, with few others (they
can be called min and max) can be given to int type itself.
D is a very nice language, that I hope to see more used. It is copying
lot of things from Python. D Floating point values have some
proprieties:

http://www.digitalmars.com/d/property.html

Properties for Floating Point Types:
.init initializer (NaN)
.infinity infinity value
.nan NaN value
.dig number of decimal digits of precision
.epsilon smallest increment
.mant_dig number of bits in mantissa
.max_10_exp maximum exponent as power of 10
.max_exp maximum exponent as power of 2
.min_10_exp minimum exponent as power of 10
.min_exp minimum exponent as power of 2
.max largest representable value that's not infinity
.min smallest representable value that's not 0
.re real part
.im imaginary part

I think such attributes may be useful to be added to Python float
type/values too.

Bye,
bearophile
The thing about float is that people expect it to be 'fast'. Most CPU's
have two or one representationfor floats that is supported by hardware
and lightning fast compared to a pure software implementation.
The decimal module provides for the 'bean counters' out their who can't
afford to round off a penny, but I must say that this is the first
request I have seen for a flexible float where you would not have
hardware support (when hardware float support is available).

Or do you mean the ability to choose between hardware supported float
s? e.g. float and double precision?
Or to be able to just interrogate the float implementation so your prog
can adjust to whatever implementation it is running under?
Something like:
assert float.mant_dig 20
- Paddy.

Aug 5 '06 #3
Paddy:
Or do you mean the ability to choose between hardware supported float
s? e.g. float and double precision?
No, I mean just having the ability to ask the float (his attribute)
what are the max and min values it can represent, etc.

stop = float.max
....

I don't know any simple way to know that values now. And importing sys
to know the max int looks stupid.

maxi = int.max
mini = int.min
....

Such attributes can be given to the Decimal values too, if you want.

Bye,
bearophile

Aug 5 '06 #4
be************@lycos.com wrote:
>
sys.maxint gives the largest positive integer supported by Python's
regular integer type. But maybe such attribute, with few others (they
can be called min and max) can be given to int type itself.
D is a very nice language, that I hope to see more used. It is copying
lot of things from Python.
I don't see that. It looks rather like an incremental improvement to C and
C++ rather than a language influenced by Python.
>D Floating point values have some proprieties:

http://www.digitalmars.com/d/property.html

Properties for Floating Point Types:
.init initializer (NaN)
.infinity infinity value
.nan NaN value
.dig number of decimal digits of precision
.epsilon smallest increment
...
There's an interesting philosophical difference here. D is defined as a
"systems programming language". It is compiled to native machine code,
like C. In such a case, the programmer necessarily needs to concern
himself with the processor's representation of integers and floats.

Python has a rather different focus. I certainly use it for system
programming tasks, but in most cases, a Python programmer shouldn't need to
worry about the internal representation of variables. Look, for example,
at the blurred distinction between integers and long integers.

I'm not arguing for or against the proposal, but I suspect these properties
would be rarely used.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Aug 6 '06 #5

be************@lycos.com wrote:
Paddy:
Or do you mean the ability to choose between hardware supported float
s? e.g. float and double precision?

No, I mean just having the ability to ask the float (his attribute)
what are the max and min values it can represent, etc.

stop = float.max
...

I don't know any simple way to know that values now. And importing sys
to know the max int looks stupid.

maxi = int.max
mini = int.min
...

Such attributes can be given to the Decimal values too, if you want.

Bye,
bearophile
Hi bearophille,
decimals have their context; maybe floats could have your read-only
'context' values made available somehow. I don't know if their is an
issue with making this (static) data available from all float
instances, so maybe it should go in sys.

Maybe people, (me included), don't pay enough attention to the
trade-offs inherent in floating point arithmatic. I was taught about
difference equations, and rounding errors. I regularly compute answers
in programs without regard to floating point precision because the
defaults chosen work for most of my cases, but if I needed to be more
precise then I too would need some of the info you suggest.

Question: do the scientific packages supported by Python supply this
data in a regular manner?

- Paddy.

P.S. My appologies to any professional 'counters of currencies' out
their who may have been offended by my earlier use of the term 'bean
counters' - You probably earn much more than me - don't call in my
loans - I have babes in arms to feed.... :-)

Aug 6 '06 #6

Paddy wrote:
be************@lycos.com wrote:
Paddy:
Or do you mean the ability to choose between hardware supported float
s? e.g. float and double precision?
No, I mean just having the ability to ask the float (his attribute)
what are the max and min values it can represent, etc.

stop = float.max
...

I don't know any simple way to know that values now. And importing sys
to know the max int looks stupid.

maxi = int.max
mini = int.min
...

Such attributes can be given to the Decimal values too, if you want.

Bye,
bearophile
Hi bearophille,
decimals have their context; maybe floats could have your read-only
'context' values made available somehow. I don't know if their is an
issue with making this (static) data available from all float
instances, so maybe it should go in sys.

Maybe people, (me included), don't pay enough attention to the
trade-offs inherent in floating point arithmatic. I was taught about
difference equations, and rounding errors. I regularly compute answers
in programs without regard to floating point precision because the
defaults chosen work for most of my cases, but if I needed to be more
precise then I too would need some of the info you suggest.

Question: do the scientific packages supported by Python supply this
data in a regular manner?

- Paddy.

P.S. My appologies to any professional 'counters of currencies' out
their who may have been offended by my earlier use of the term 'bean
counters' - You probably earn much more than me - don't call in my
loans - I have babes in arms to feed.... :-)
P.P.S. Just looking at the values you propose, if some of them can be
computed reliably from others (in the given float precision), then they
should NOT be included, but the module documentation should state how
they can be derived.

Aug 6 '06 #7
Paddy wrote:
Question: do the scientific packages supported by Python supply this
data in a regular manner?
For floating point types, at least.

In [11]: from numpy import *

In [12]: print finfo(float32)
Machine parameters for <type 'float32scalar'>
---------------------------------------------------------------------
precision= 6 resolution= 1.0000000e-06
machep= -23 eps= 1.1920929e-07
negep = -24 epsneg= 5.9604645e-08
minexp= -126 tiny= 1.1754944e-38
maxexp= 128 max= 3.4028235e+38
nexp = 8 min= -max
---------------------------------------------------------------------
In [13]: print finfo(float64)
Machine parameters for <type 'float64scalar'>
---------------------------------------------------------------------
precision= 15 resolution= 1.0000000000000001e-15
machep= -52 eps= 2.2204460492503131e-16
negep = -53 epsneg= 1.1102230246251565e-16
minexp= -1022 tiny= 2.2250738585072014e-308
maxexp= 1024 max= 1.7976931348623157e+308
nexp = 11 min= -max
---------------------------------------------------------------------
--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Aug 6 '06 #8
Self:
>>D is a very nice language, that I hope to see more used. It is copying
lot of things from Python.
Tim Roberts:
>I don't see that. It looks rather like an incremental improvement to C and
C++ rather than a language influenced by Python.
Thank you for your comments. Mine was probably just an illusion. In D
most things are copied or come directly from C++. But I like the built
in string and associative array management, the string/array slicing,
the multiple return or typed multiple input, the nested functions, the
foreach with a bit of type inferencing, and some other things that I
like in Python too, but absent in C++ (GCC has some nested functions,
etc).
(But D lacks some of the suggestions in this article, link coming from
Paddy:
http://www.cs.princeton.edu/~dpw/popl/06/Tim-POPL.ppt )

This is the first thing written about D into its site:
http://www.digitalmars.com/d/
>D is a systems programming language. Its focus is on combining the power and high performance of C and C++ with the programmer productivity of modern languages like Ruby and Python.<
This is a thread about related matters, with a comment from Walter, the
D autor:
http://www.digitalmars.com/d/archives/19839.html

Bye,
bearophile

Aug 6 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: TheKeith | last post by:
Is it just me or does opera and ie not render the float style properly? IE does a sucky job at it, but opera makes a total mess; Mozilla/Firefox renders it correctly however. I'm just trying to be...
1
by: Jan Agermose | last post by:
Im writing a small test app that reads stringvalues, parses them to doubles and inserts the doubles into a mssql database. But the values inserted are not the same as the original string values? ...
161
by: KraftDiner | last post by:
I was under the assumption that everything in python was a refrence... so if I code this: lst = for i in lst: if i==2: i = 4 print lst I though the contents of lst would be modified.....
15
by: Kay Schluehr | last post by:
I wonder why this expression works: >>> decimal.Decimal("5.5")**1024 Decimal("1.353299876254915295189966576E+758") but this one causes an error 5.5**1024 Traceback (most recent call...
8
by: abdul_n_khan | last post by:
Hello, I have a basic question related to datatypes. I am trying to read a value using Microsoft's ADO recordset from a field (lets call it 'Price') with datatype decimal(19,6) => 19 = Precision,...
6
by: trevor | last post by:
Incorrect values when using float.Parse(string) I have discovered a problem with float.Parse(string) not getting values exactly correct in some circumstances(CSV file source) but in very similar...
2
by: Abra | last post by:
Hello, I am using the XmlSerializer clas to serialize/deserialize XML files. I have a XML file containing elements which have attributes of type float. If the value of the float attribute in my...
10
by: mark | last post by:
I'm brushing up on my CSS, already running into problems with IE 6 The follow code should display two divs adjacent to each other within a container. The problem is in IE6 the left div starts a...
0
by: Terry Reedy | last post by:
Prashant Saxena wrote: A property with a working get and set that raises an exception. Don't know. I believe this is what slots is for.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.