Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Algrbra Package
#16
wavic,

Wrong. Read the documentation for the python package decimal. Here's the intro:

"The decimal module provides support for decimal floating point arithmetic. It offers several advantages over the float datatype:

Decimal “is based on a floating-point model which was designed with people in mind, and necessarily has a paramount guiding principle – computers must provide an arithmetic that works in the same way as the arithmetic that people learn at school.” – excerpt from the decimal arithmetic specification.

Decimal numbers can be represented exactly. In contrast, numbers like 1.1 and 2.2 do not have exact representations in binary floating point. End users typically would not expect 1.1 + 2.2 to display as 3.3000000000000003 as it does with binary floating point.

The exactness carries over into arithmetic. In decimal floating point, 0.1 + 0.1 + 0.1 - 0.3 is exactly equal to zero. In binary floating point, the result is 5.5511151231257827e-017. While near to zero, the differences prevent reliable equality testing and differences can accumulate. For this reason, decimal is preferred in accounting applications which have strict equality invariants.

The decimal module incorporates a notion of significant places so that 1.30 + 1.20 is 2.50. The trailing zero is kept to indicate significance. This is the customary presentation for monetary applications. For multiplication, the “schoolbook” approach uses all the figures in the multiplicands. For instance, 1.3 * 1.2 gives 1.56 while 1.30 * 1.20 gives 1.5600.

Unlike hardware based binary floating point, the decimal module has a user alterable precision (defaulting to 28 places) which can be as large as needed for a given problem:"


Messages In This Thread
Algrbra Package - by kmcollins - Feb-02-2018, 07:42 PM
RE: Algrbra Package - by Mekire - Feb-02-2018, 10:33 PM
RE: Algrbra Package - by kmcollins - Feb-02-2018, 11:50 PM
RE: Algrbra Package - by kmcollins - Feb-03-2018, 11:11 PM
RE: Algrbra Package - by Gribouillis - Feb-04-2018, 12:31 AM
RE: Algrbra Package - by Windspar - Feb-04-2018, 02:55 PM
RE: Algrbra Package - by kmcollins - Feb-04-2018, 07:30 PM
RE: Algrbra Package - by kmcollins - Feb-06-2018, 12:02 AM
RE: Algrbra Package - by wavic - Feb-06-2018, 02:17 AM
RE: Algrbra Package - by kmcollins - Feb-06-2018, 04:22 PM
RE: Algrbra Package - by Gribouillis - Feb-06-2018, 06:11 PM
RE: Algrbra Package - by wavic - Feb-06-2018, 07:50 PM
RE: Algrbra Package - by kmcollins - Feb-06-2018, 09:54 PM
RE: Algrbra Package - by micseydel - Feb-06-2018, 11:02 PM
RE: Algrbra Package - by wavic - Feb-07-2018, 06:10 AM
RE: Algrbra Package - by kmcollins - Feb-07-2018, 09:06 PM
RE: Algrbra Package - by Gribouillis - Feb-07-2018, 09:37 PM
RE: Algrbra Package - by Mekire - Feb-08-2018, 01:45 AM
RE: Algrbra Package - by metulburr - Feb-08-2018, 02:02 AM
RE: Algrbra Package - by kmcollins - Feb-08-2018, 10:04 PM
RE: Algrbra Package - by Gribouillis - Feb-08-2018, 10:17 PM
RE: Algrbra Package - by kmcollins - Feb-08-2018, 11:26 PM
RE: Algrbra Package - by metulburr - Feb-08-2018, 11:52 PM
RE: Algrbra Package - by Mekire - Feb-09-2018, 04:47 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020