An official Batch Programming blog! To Solve the daily problems with windows and fixing them with little notepad scripts. Unlock the Hidden Secrets of Windows, Learn to crack Software via CMD & Make your own Programming tools. Understand to Manipulate your PC via CMD.

Algorithm for calculating floating point numbers | By kvc

BASIC ALGORITHM FOR FLOATING POINT NUMBERS: As we already know, CMD only deals with INTEGERS. And it is not possible to calculate Floating point numbers / Decimal Numbers simply.

I Share this Knowledge, because I think it is the Right thing to do.

Kvc

But, we were trying to find a solution to this problem. And, we have created an almost proper algorithm for calculating Floating point numbers from a 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. Thus, You can expect some So, without wasting any time, let’s talk about the Algorithm.

The algorithm is divided into 3 parts:

  1. Plus (+) and (-) operations,
  2. For Multiplication (x) operations,
  3. For Division (/) operations.

Now, In general, we have to make some assumptions in order to create something. The same case is here, as we have assumed some facts before making this awesome algorithm for Floating Point Numbers.

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’

  1. The Part Before ‘dot’ (.)
  2. The Part After ‘dot’ (.)

Example

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 the same decimal places. Like we can’t just simply add 36 to 649, it will mess-up with our result.
  2. We have to make 36 to 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.
  3. 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 in the Final Result.
    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
  4. 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 the same (same as in the 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…
Also Read:  Protect Personal Data with Notepad Tricks | Locker 1.0 By Anonymous

Examples are BEST – Let’s See an Example:

Division Algorithm Explained

Final Thoughts: ALGORITHM FOR FLOATING POINT NUMBERS

So finally, this Amazing Post ends. And, if in case you didn’t get anything from the above explanation or You like my work about Batch Programming, then please leave me a comment down this post.

If you have any suggestions then you’re most welcome, and if these batch trick helps you in any of your work – Feel free to say thanks to me – Because, you’ll not lose anything by saying Thanks!

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

TheBATeam

Next Post

Previous Post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2020 TheBATeam

Terms & Conditions   /   Privacy Policy   /   Why Register?

Theme by Anders Norén