Read Mode

Algorithm for calculating floating point numbers in Batch | By kvc

Hey hello Guys, Today I'm Gonna share one of my best batch programming work, as we have created an 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 the computer programming. This algorithm 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:

  1. For Plus (+) and (-) operations,
  2. For Multiplication (x) operations,
  3. 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. We were working on this project, and while having our copy and pen on desk. we thought of the following basic fact.

'As we know that every float value has two parts.'

  1. The Part Before 'dot' (.)
  2. The Part After 'dot' (.)
Algorithm for calculating floating point numbers in cmd | By kvc

Considering Cases:

  1. 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 becomes 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.

  2. 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 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 dot is 5…

    Now simply multiply 239 & 3649 and Place a Dot ‘.’ Leaving last 5 digits of answer.  e.g. 2.36 * 3.649 = 8.61164

  3. And the algorithm for dividing the two floating point numbers is somewhat a mixture of the above two algorithms… i.e. 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 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 result and we place dot leaving same number of digits of result as ‘zeros’ in the multiplier. 
    Try to understand above paragraph with following example…
Algorithm for calculating floating point numbers in Batch | By kvc
Division Algorithm Explained
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… or you can also mail me at Just do leave comment or An E-mail, even if you don’t like the way I represent things and 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 loose anything by saying Thanks…

Keep learning, keep sharing…
Be happy, spread happiness…

Download Document File : Floating Point Algorithm.docx


No comments:

Powered by Blogger.