ALGORITHM FOR CALCULATING FLOATING POINT NUMBERS :Hey Guys, Today I’m Gonna share one of my best batch programming work.
As we have created a proper algorithm for calculating Floating point numbers from pure Integer environment.
In other words, we may have found the way of windows to define floating point integers in computer programming.
This is fully created by kvc, and not even a single info about floating point values is taken from any other source.
So, without wasting any time, let’s talk about the Algorithm.
The algorithm is divided into 3 parts:
- Plus (+) and (-) operations,
- For Multiplication (x) operations,
- For Division (/) operations.
Now, In general, we have to take some assumptions in order to create something, the same case is here, as we have assumed some facts before making this awesome algorithm.
ALGORITHM FOR CALCULATING FLOATING POINT NUMBERS
We were working on this project, and while having our copy and pen on the desk. we thought of the following basic fact.
‘As we know that every float value has two parts’
- The Part Before ‘dot’ (.)
- The Part After ‘dot’ (.)
- If we want to add two floating point values then… e.g. 2.36 + 3.649 = 6.009
We can add Part 1 & Part 2 of both numbers separately but to do so, we have to make Part 2 of Both numbers in same decimal places. Like we can’t just simply add 36 to 649, it will mess-up with our result.
- We have to make 36 à 360 first (so that decimal places become same i.e. 3 digits after dot ‘.’) then we can add Part 2 of both numbers and adding Part 1 of both the numbers will be easier enough,
Similar operations are valid for subtracting floating point numbers. The Negative sign will be handled via two ‘If‘ statements in the code.
- And Algorithm for multiplying two floating point numbers is very easier than all others… As we just have to count the total no. of digits after dot ‘.’ in both the Numbers… i.e.
- In the above case, Number 1 (2.39) has 2 digits after dot ‘.’ And Number 2 (3.649) has 3 digits after dot ‘.’, hence the total number of digits after the dot is 5…
Now simply multiply 239 & 3649 and Place a Dot ‘.’ Leaving the last 5 digits of the answer. e.g. 2.36 * 3.649 = 8.61164
- And the algorithm for dividing the two floating point numbers is somewhat a mixture of the above two algorithms.
- First we have to make the decimal places of numbers same (same as in 1st algorithm) and then we can count the total number of the digits after the dot and then perform simple division operation.
- The only change in this algorithm is that we have to multiply the number firstly with a multiplier which is 10000 of any other multiple of 10 so that on division,
- We don’t lose any part of the result and we place dot leaving the same number of digits of the result as ‘zeros’ in the multiplier.
Try to understand the above paragraph with the following example…
So, finally this Amazing Post ends and if in case you didn’t get anything from the above explanation or like my work about Batch Programming, then please leave me a comment down this post.
Just do leave a comment or An E-mail, even if you don’t like the way I represent things.
If you have any suggestion then you’re most welcome and if this trick helps you in any of your work feel free to say thanks to me’cuz you’ll not lose anything by saying thanks…
Keep learning, keep sharing….TheBATeam
Be happy, spread happiness…