CS 215: On Numeric Data Types implementation

Philippines
December 12, 2007 12:20am CST
If you were asked to design a particular PL, which implementation would you use for your float data types : Floating points or Decimal data types ? Present your arguments or discuss the advantages of one over the other.
1 person likes this
3 responses
@bojhe24 (12)
• Philippines
12 Dec 07
There are many programming domains and designing a PL for a certain domain may either be for floating points or decimal. For instance, if I am going to design PL for business applications, I may go for decimal since it holds fix decimal parts values. Business computations are done with whole numbers and/or of decimal only, commonly. Having that, I would save space allocation for variables. But decimal won't suffice every programming domain, like a PL handling 3D computation to draw certain figure. That requires exact calculation to do the simulation or such and since floating points offer flexible decimal parts. What drawback we can notice here is that it would require much space but that's a part already in optimizing your overall codes. It is crucial indeed to make into consideration your programming domain before designing PL.
1 person likes this
• Philippines
13 Dec 07
good point you have made there.... let me add to the application of floating point representation in scientific computations or simulations like weather forcasting, intelligent systems, AI systems , etc.
@riveream (111)
• Philippines
16 Dec 07
If I were asked to design a particular PL, I think that the implementation that I will use will depend on the particular PL that I will design. The values of floating points are represented as fractions and exponents. The collection of values that can be represented by a floating-point type is defined in terms of precision and range, Precision is the accuracy of the fractional part of a value while range is a combiantion of the range of fractions and exponents. And also if I am going to use a floating point, I should also know what kind of representations (e.g. single precision or double precision) is supported by the hardware. If the hardware does not support the floating-point operations, then these operations will be emulated in software, which can be 10 to 100 times slower than their hardware counterparts. Its disadvantage floating points is its loss of accuracy through arithmetic operations. If I am going to design a PL used to support business systems applications, then I will have to use decimal data types. It stores a fixed number of decimal digits. Decimal types have the advantage of being capable of precisely storing decimal values- at least those within a restricted range- which cannot be done in floating point. The disadvantage is that the range of values is restricted because no exponents are allowed, and their representation in memory is wasteful. The operations on decimal values are doen in hardware on machines that have such capabilities; otherwise they are performed in software.
@paulit03 (93)
• Philippines
16 Dec 07
i do agree with bojeh24... by using decimal data types it stores a fixed number of decimal digits. by having a fixed decmial it will give us the accurate number that we wanted too have. unlike the floating data types it will just give us the estimated number. therefore if the program that we are going to create that needs the accurate number i will recommend that he choose decimal data types. but if the program is only the estimated form of a number he can choose either decimal or floating data types. the advantage of decimal is that it has a fixed number.