SEF9 - 56 Programming Concepts Lesson 05 (Avoiding overflow using Python Decimal datatype)

This Python program is a rerun of the C-program that demonstrates overflow errors for data types integers, floats and doubles. The rerun is introduced in this python program at Sections A, B and C, but this time we use the data type "Decimal" in python. Ha ha ha.

This program also introduces the data type "float" in python. The computations are also compared to the "Decimal" data type in python.


============================================
Tutorial Learning points and Discussions
============================================

(1) All calculations using floating point representation of real numbers are approximate, because real numbers cannot be exactly represented in floating point representations. The real numbers are rounded up or rounded down to their closest floating point representations.

(2) Floating point computations accumulate their approximation errors. We have to minimize computations by seeking the minimum number of mathematical operations needed to achieve the same computation, because each mathematical operation will introduce an approximation error.

(3) Think of the "Python programming” (Decimal data type) for obvious reasons of course. And even in python, to avoid errors in numerical computations, do not forget to do “Error Trappings”. There is no overflow using Decimal datatype in Python.

(4) Know exactly what you are doing, what you are calculating. Know what input ranges you intend to run in your program, trap anything outside these ranges. Know the intermediate calculated ranges that you are expecting for correct operations, again trap anything outside these expected ranges. Know the output results that you expect in your program, again trap anything outside these expected output ranges.

(5) Parallel computing allows many computations to be conducted simultaneously. It provides speedup, i.e. give results faster. However, the considerations are different between serial programs and parallel programs, and are to be handled differently.



--
WASSALAM
wruslan.hahaha

Attachments:
SEF-Example-Python-Decimal-does-not-overflow.pdf

Full Version with Microsoft Word Version and Attachments
Return to Software Engineering Fundamentals (SEF9MMUWRY)
Previous Topic: 55 Programming Concepts Lesson 04 (Floating Point numbers are not exact)
Next Topic: 57 Programming Concepts Lesson 06 (Simple parallel programming in C)

0 comments:

Post a Comment