473,756 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Math errors in python

In python 2.3 (IDLE 1.0.3) running under windows 95, I get the
following types of errors whenever I do simple arithmetic:

1st example:
12.10 + 8.30 20.399999999999 999 1.1 - 0.2 0.9000000000000 0013
2nd example(no errors here): bool(130.0 - 129.0 == 1.0) True
3rd example: a = 0.013
b = 0.0129
c = 0.0001
[a, b, c] [0.0129999999999 99999, 0.0129, 0.0001] bool((a - b) == c)

False
This sort of error is no big deal in most cases, but I'm sure it could
become a problem under certain conditions, particularly the 3rd
example, where I'm using truth testing. The same results occur in all
cases whether I define variables a, b, and c, or enter the values
directly into the bool statement. Also, it doesn't make a difference
whether "a = 0.013" or "a = 0.0130".

I haven't checked this under windows 2000 or XP, but I expect the same
thing would happen. Any suggestions for a way to fix this sort of
error?
Jul 18 '05
89 5136
Note: I posted a response yesterday, but it apparently never appeared (I
was having some trouble with my newsreader) so I'm posting this now. My
apologies if it is a duplicate.

Alex Martelli wrote:
Paul Rubin <http://ph****@NOSPAM.i nvalid> wrote:
...
The issue here is that Python's behavior confuses the hell out of some
new users. There is a separate area of confusion, that

a = 2 / 3

sets a to 0, and to clear that up, the // operator was introduced and
Python 3.0 will supposedly treat / as floating-point division even
when both operands are integers. That doesn't solve the also very
common confusion that (1.0/3.0)*3.0 = 0.99999999. Rational arithmetic
can solve that.

Yes, but applying rational arithmetic by default might slow some
computations far too much for beginners' liking! My favourite for
Python 3.0 would be to have decimals by default, with special notations
to request floats and rationals (say '1/3r' for a rational, '1/3f' for a
float, '1/3' or '1/3d' for a decimal with some default parameters such
as number of digits). This is because my guess is that most naive users
would _expect_ decimals by default...


I agree. Naive (eg, non-CS, non-Mathemetician/Engineer) users who grew
up with calculators and standard math courses in school may have never
even heard of floats! (I made it as far as Calculus 2 in college, but
still had never heard of them.)

This brings me to another issue. Often c.l.py folks seem surprised that
people don't RTFM about floats before they ask about why their math
calculations aren't working. Most of the folks asking have no idea they
are *doing* float arithmetic, so when they try to google for the answer,
or look in the docs for the answer, and skip right past the "Float
Arithmetic" section of the FAQ and the Tutorial, it's because they're
not DOING float arithmetic - that they know of... So, of course they
won't read those sections to look for their answer, any more than they'd
read the Complex Number calculations section... People who know about
floats con't need that section - the ones who do need it, con't know
they need it.

If you want people to find those sections when they are looking for
answers to why their math calculations aren't working - I suggest you
remove the "FLOAT" from the title. Something in the FAQ like: "Why are
my math calculations giving weird or unexpected results?" would attract
a lot more of the people you WANT to read it. Once you've roped them in,
*then* you can explain to them about floats...

Anna Martelli Ravenscroft
Jul 18 '05 #81
Anna Martelli Ravenscroft wrote:
If you want people to find those sections when they are looking for
answers to why their math calculations aren't working - I suggest you
remove the "FLOAT" from the title. Something in the FAQ like: "Why are
my math calculations giving weird or unexpected results?" would attract
a lot more of the people you WANT to read it. Once you've roped them in,
*then* you can explain to them about floats...


Excellent point.

(Or, "+1" as the "oldbies" say. ;-) )

Nice to "meet" you, too -- welcome! (Even if I'm primarily only a
lurker.)

(Alex mentioned you have a Fujitsu LifeBook -- I do, too, and like it
very much!)

---

[Note: I am having equipment and connectivity problems. I'll be back
as I can when I get things sorted out better, and as appropriate (or
inappropriate ;-) ). Thanks to you and to all for the civil
and fun discussions!]
Richard Hanson

--
sick<PERI0D>old <P0INT>fart<P IE-DEC0-SYMB0L>newsguy< MARK>com
Jul 18 '05 #82
Richard Hanson <me@privacy.net > wrote:
...
(Alex mentioned you have a Fujitsu LifeBook -- I do, too, and like it
very much!)


There are many 'series' of such "Lifebooks" nowadays -- it's become as
un-descriptive as Sony's "Vaio" brand or IBM's "Thinkpad". Anna's is a
P-Series -- 10.5" wide-form screen, incredibly tiny, light, VERY
long-lasting batteries. It was the _only_ non-Apple computer around at
the local MacDay (I'm a Mac fan, and she attended too, to keep an eye on
me I suspect...;-), yet it got nothing but admiring "ooh!"s from the
crowd of design-obsessed Machies (Apple doesn't make any laptop smaller
than 12", sigh...).

OBCLPY: Python runs just as wonderfully on her tiny P-Series as on my
iBook, even though only Apple uses it within the OS itself;-)
Alex
Jul 18 '05 #83
[Connection working again...?]

Alex Martelli wrote:
Richard Hanson <me@privacy.net > wrote:
...
(Alex mentioned you have a Fujitsu LifeBook -- I do, too, and like it
very much!)
There are many 'series' of such "Lifebooks" nowadays -- it's become as
un-descriptive as Sony's "Vaio" brand or IBM's "Thinkpad". Anna's is a
P-Series -- 10.5" wide-form screen, incredibly tiny, light, VERY
long-lasting batteries.


Ahem. As I said ;-) in my reply to your post mentioning Anna's P2000
(in my MID: <lg************ *************** *****@4ax.com>) , and in
earlier postings re 2.4x installation difficulties, mine is a Fujitsu
LifeBook P1120. (Sorry, Alex! I definitely *should* have mentioned the
model again -- I'm just beginning to appreciate the difficulty of even
*partially* keeping up with c.l.py. I'm learning, though. :-) )

In any event, the Fujitsu LifeBook P1120 has a 8.9" wide-format
screen, is 2.2lbs.-light with the smaller *very* long-lasting battery
and 2.5lbs.-light with the very, *very* long-lasting battery, and has
-- what tipped the scales, as it were, for my needs -- a touchscreen
and stylus.
It was the _only_ non-Apple computer around at
the local MacDay (I'm a Mac fan, and she attended too, to keep an eye on
me I suspect...;-), yet it got nothing but admiring "ooh!"s from the
crowd of design-obsessed Machies (Apple doesn't make any laptop smaller
than 12", sigh...).
I can feel your pain. I would switch to Apple in a second if they had
such light models (and if I had the bucks ;-) ). I need a very light
machine for reasons specified earlier. (Okay, slightly reluctantly:
Explicit may be better even with *this* particular info -- I have
arthritis [ankylosing spondylitis] and need very light laptops to read
and write with. :-) )
OBCLPY: Python runs just as wonderfully on her tiny P-Series as on my
iBook, even though only Apple uses it within the OS itself;-)


ObC.l.pyFollow-up: Python also runs very well on my tinier ;-) P1120
with the Transmeta Crusoe TM5800 processor running at 800MHz and with
256MB RAM and a 256KB L2 on-chip cache -- even using Win2k. :-) It's
really nice not needing a fan on a laptop, as well -- even when
calculating Decimal's sqrt() to thousands of decimal places. ;-)

ObExplicit-metacomment: I'm only attempting a mixture of info *and*
levity. :-)
what?-men-arguing-about-whose-is-*tinier*?!'ly y'rs,
Richard Hanson

--
sick<PERI0D>old <P0INT>fart<P IE-DEC0-SYMB0L>newsguy< MARK>com
Jul 18 '05 #84
In article <ad************ *************** *****@4ax.com>,
Richard Hanson <me@privacy.net > wrote:
[Connection working again...?]

Alex Martelli wrote:
Richard Hanson <me@privacy.net > wrote:
...
> (Alex mentioned you have a Fujitsu LifeBook -- I do, too, and like it
> very much!)

Jul 18 '05 #85
Cameron Laird wrote:
In article <ad************ *************** *****@4ax.com>,
Richard Hanson <me@privacy.net > wrote [comparing
Anna Martelli Ravenscroft's Fujitsu LifeBook P2000 to my
(Richard Hanson's) Fujitsu LifeBook P1120]:
[...]

In any event, the Fujitsu LifeBook P1120 has a 8.9" wide-format
screen, is 2.2lbs.-light with the smaller *very* long-lasting battery
and 2.5lbs.-light with the very, *very* long-lasting battery, and has
-- what tipped the scales, as it were, for my needs -- a touchscreen
and stylus.

[...]

Alex Martelli wrote:
OBCLPY: Python runs just as wonderfully on her tiny P-Series as on my
iBook, even though only Apple uses it within the OS itself;-)
ObC.l.pyFoll ow-up: Python also runs very well on my tinier ;-) P1120
with the Transmeta Crusoe TM5800 processor running at 800MHz and with
256MB RAM and a 256KB L2 on-chip cache -- even using Win2k. :-) It's
really nice not needing a fan on a laptop, as well -- even when
calculating Decimal's sqrt() to thousands of decimal places. ;-)

.
.
.
Is Linux practical on these boxes?


I've found on the web accounts of two people, at least, getting the
P1120 working with Linux and with at least partial functionality of
the touchscreen -- one individual claimed full functionality. (I found
some accounts of success with getting Linux working on the P2000, as
well.) I'm currently waiting to purchase a new harddrive for my P1120
to see for myself if I can get Linux installed with the touchscreen
fully functioning -- which, as I mentioned in my post, is particularly
important to me.
How do touch-typists like them


I've been touch-typing since I was about nine-years-old. When I was
looking for a very light laptop for reasons mentioned in my post, I
was concerned that I wouldn't be able to touch-type on the ~85% (16mm
pitch) keyboard. I went to a local "big box" computer store (who shall
remain nameless) and tried one of the P1120s -- within seconds I
realized I could easily adapt and subsequently ordered one from
Fujitsu.

I would estimate that I was typing *faster* and with substantially
*fewer* errors inside of several weeks -- and occasional uses of the
standard-sized keyboard on my HP Omnibook 900B made me feel like a
Munchkin. :-)

Now that I'm temporarily back on the standard-pitch Omnibook 900B, I
have adapted to the what-had-come-to-seem-a-humongous keyboard, once
again. I most definitely prefer the P1120's keyboard.

I note that on the P1120, I could reach difficult key-combinations
much easier, and also, that I could often hold down two keys of a
three-key combo, say, with one finger or thumb.

Your mileage may vary, as they say, but I now prefer smaller
keyboards.

The "instant on-off" works very well, too. I highly recommend the
P1120 for anyone who isn't put off by the smaller keyboard. (Drawing
on the screen with the stylus is pretty trick, as well.)
Richard Hanson

--
sick<PERI0D>old <P0INT>fart<P IE-DEC0-SYMB0L>newsguy< MARK>com
Jul 18 '05 #86
Cameron Laird <cl****@lairds. us> wrote:
...
Is Linux practical on these boxes?
Never got 'sleep' to work (there's supposed to be a 'hybernate' thingy,
but I haven't found it to work reliably either). AFAIMC, that's the
biggie; everything else is fine.
How do touch-typists like them


Just fine (the 10.5" P2000 -- can't speak for the even-smaller P1000s).
Alex
Jul 18 '05 #87
Cameron Laird wrote:
In article <ad************ *************** *****@4ax.com>,
Richard Hanson <me@privacy.net > wrote:
[Connection working again...?]

Alex Martelli wrote:

Richard Hanson <me@privacy.net > wrote:
...

(Alex mentioned you have a Fujitsu LifeBook -- I do, too, and like it
very much!)


.
.
.
Ahem. As I said ;-) in my reply to your post mentioning Anna's P2000
(in my MID: <lg************ *************** *****@4ax.com>) , and in
earlier postings re 2.4x installation difficulties, mine is a Fujitsu
LifeBook P1120. (Sorry, Alex! I definitely *should* have mentioned the
model again -- I'm just beginning to appreciate the difficulty of even
*partially* keeping up with c.l.py. I'm learning, though. :-) )

In any event, the Fujitsu LifeBook P1120 has a 8.9" wide-format
screen, is 2.2lbs.-light with the smaller *very* long-lasting battery
and 2.5lbs.-light with the very, *very* long-lasting battery, and has
-- what tipped the scales, as it were, for my needs -- a touchscreen
and stylus.


.
.
.
I can feel your pain. I would switch to Apple in a second if they had
such light models (and if I had the bucks ;-) ). I need a very light
machine for reasons specified earlier. (Okay, slightly reluctantly:
Explicit may be better even with *this* particular info -- I have
arthritis [ankylosing spondylitis] and need very light laptops to read
and write with. :-) )

OBCLPY: Python runs just as wonderfully on her tiny P-Series as on my
iBook, even though only Apple uses it within the OS itself;-)


ObC.l.pyFollo w-up: Python also runs very well on my tinier ;-) P1120
with the Transmeta Crusoe TM5800 processor running at 800MHz and with
256MB RAM and a 256KB L2 on-chip cache -- even using Win2k. :-) It's
really nice not needing a fan on a laptop, as well -- even when
calculating Decimal's sqrt() to thousands of decimal places. ;-)


.
.
.
Is Linux practical on these boxes? How do touch-typists like them


Well, mine is dual boot. I'm currently experimenting with Ubuntu on my
Linux partition... I'm really REALLY hoping for a linux kernel with a
decent 'sleep' function to come up RSN because I despise having to work
in Windoze XP instead of Linux. Ah well, at least the XP hasn't been too
terrible to work on - it runs surprisingly smoothly, particularly with
Firefox and Thunderbird for browsing and email...

And I can touch type just fine - except for the damn capslock key (there
is NO purpose whatsoever for a capslock key as a standalone key on a
modern keyboard, imho). I've had only minor problems with the touch
typing that I do - and that, only due to the slightly different layout
of the SHIFT key on the right side compared to where I'd normally expect
to find it: keyboard layout is a common bugbear on laptops though,
regardless of size....

Anna
Jul 18 '05 #88
Anna Martelli Ravenscroft wrote:

[This post primarily contains solutions to Anna's problem with the
Fujitsu LifeBook P2000's key locations. But, there's also some 2.4x
MSI Installer anecdotal info in my footnote.]
Cameron Laird wrote:
Is Linux practical on these boxes? How do touch-typists like them
Well, mine is dual boot. I'm currently experimenting with Ubuntu on my
Linux partition... I'm really REALLY hoping for a linux kernel with a
decent 'sleep' function to come up RSN because I despise having to work
in Windoze XP instead of Linux. Ah well, at least the XP hasn't been too
terrible to work on - it runs surprisingly smoothly, particularly with
Firefox and Thunderbird for browsing and email...


My Fujitsu LifeBook P1120 is (was) only single-booting Win2k, so I
can't help with the Linux "sleep" function as yet -- I'll be working
on dual-booting Win2k and Linux on the P1120 as soon as I get the
requisite hardware to rebuild things. The "sleep" function is a *very*
high priority for me, so if and when I find a solution, I'll post it
if you're still needing such -- may well work for your P2000 as well.
And I can touch type just fine - except for the damn capslock key (there
is NO purpose whatsoever for a capslock key as a standalone key on a
modern keyboard, imho).
It seems *many* folks agree; read below.
I've had only minor problems with the touch
typing that I do - and that, only due to the slightly different layout
of the SHIFT key on the right side compared to where I'd normally expect
to find it: keyboard layout is a common bugbear on laptops though,
regardless of size....


[I lost all my recent archives in a recent series of "crashes" -- so I
regoogled this morning for the info herein.]

On Win2k, and claimed for WinXP, one can manually edit the registry to
remap any of the keys. I originally did this on my P1120 with Win2k.
Worked just fine.

(I had saved to disc before a Win98SE crash just a few minutes ago
;-), the manual regedit values. If you're interested in 'em you may
post here or contact me off-group. The email addie below works if
unmunged -- ObExplicit: replace the angle-bracketed items with the
appropriate symbol.)

Also, there are tools available from both MS, and for those who don't
like to visit MS ;-), free from many other helpful folks.

If my memory serves, I liked best the (freeware, I believe) tool
KeyTweak:

<http://webpages.charte r.net/krumsick/KeyTweak_instal l.exe>

available from this page:

<http://webpages.charte r.net/krumsick>

---

MS's tool is Remapkey.exe. (NB: I have not tried this tool --
*usually* my firewall blocks MS :-) [which required an unblocking to
install 2.4ax because of the new MSI Installer[1] :-) ].) This tool
may already be on one of your MS CDs in the reskit dirs (I haven't
looked in mine).

In any event, one webpage:

<http://www.annoyances. org/exec/forum/winxp/t1014389848>

describes Remapkey.exe as:

"... a nifty tool put out by microsoft (sic). Make sure you get the
correct version for your OS. Not resource intensive like other dll
apps."

The page has these links (quoted herein):

For individual downloads:
<http://www.dynawell.co m/support/ResKit/winxp.asp>

Free from Microsoft site, for full downloads
<http://www.microsoft.c om/downloads/details.aspx?fa milyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&di splaylang=en>

or shorter link:
<http://www.petri.co.il/download_window s_2003_reskit_t ools.htm>

---

I also have links to a few other freeware (some open-source) tools for
all versions of Win32. I won't add them now, but repost or contact me
if you want more info from my research.

---

Additionally, I found many solutions for Linux, but haven't
investigated those as (as I said) I have not yet installed Linux on my
Fujitsu LifeBook P1120. Again, if you have trouble locating a Linux
key-remapping method, let me know as I found lots of links for the
better OS :-), as well.

(I do note that after several reinstalls on the P1120, that I was
finally used to the capslock and shift key locations well enough to
avoid wrongly hitting them very often. As they say, though, your
mileage may vary.)
Richard Hanson
_______________ _______________ _____________
[1] On this HP Omnibook 900B even after downloading the requisite MSI
Install file, I experienced multiple errors trying to install 2.4a3.2
on Win98SE. I finally got 2.4x working, but I note that the helpfiles
are still missing the navigation icons. I have the MSI Installer error
messages if Martin or anyone is interested.

--
sick<PERI0D>old <P0INT>fart<P IE-DEC0-SYMB0L>newsguy< MARK>com
Jul 18 '05 #89
Alex Martelli wrote:
Cameron Laird <cl****@lairds. us> wrote:
How do touch-typists like them


Just fine (the 10.5" P2000 -- can't speak for the even-smaller P1000s).


I commented on my P1120 -- works better for me than the standard-sized
keyboards. See my MID:

<14************ *************** *****@4ax.com>
Richard Hanson

--
sick<PERI0D>old <P0INT>fart<P IE-DEC0-SYMB0L>newsguy< MARK>com
Jul 18 '05 #90

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

Similar topics

1
2077
by: TC | last post by:
I am getting small math errors when I use a query to convert a column's data type from Text to Single. I am using a calculated column with the following expression. HighSchoolGPA: IIf(IsNull(),Null,CSng()) When GPA = "3.10", HighSchoolGPA := 3.09999990463257, not 3.1. For this particular application, the difference between 3.09999990463257 and 3.1 is unacceptable.
0
9275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9843
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8713
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.