Remainder (Modulus, Modulo)


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    969


    Did you find this post helpful? Yes | No

    Default

    The answers are correct. Surprised? Here's how it works

    480/148 = 3 in integer math.
    = 3.24 in fractional math

    480 mod 148 = 36 how?
    480 - (148*3) = 36

    Then you might ask, what is the 0.24 and 36.

    When you multiply 0.24 by the divisor 148, you get the fraction that remains 36.

    If you want to do fixed place math, multiply the upper number by 100 and you will get a result that has the additional 2 digits and you put the decimal after dividing by 100.

    eg : 480 / 148 now becomes (480*100)/148
    result will be 324. This is actually 100 times greater because we multiplied by 100. So, while printing the value, you print 324/100, ".", 324 mod 100 to get the proper value of 3.24

    You might find more ports out here explaining flxed point math - search

  2. #2
    Join Date
    Nov 2009
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Jerson View Post
    The answers are correct. Surprised? Here's how it works

    480/148 = 3 in integer math.
    = 3.24 in fractional math

    480 mod 148 = 36 how?
    480 - (148*3) = 36

    Then you might ask, what is the 0.24 and 36.

    When you multiply 0.24 by the divisor 148, you get the fraction that remains 36.

    If you want to do fixed place math, multiply the upper number by 100 and you will get a result that has the additional 2 digits and you put the decimal after dividing by 100.

    eg : 480 / 148 now becomes (480*100)/148
    result will be 324. This is actually 100 times greater because we multiplied by 100. So, while printing the value, you print 324/100, ".", 324 mod 100 to get the proper value of 3.24

    You might find more ports out here explaining flxed point math - search
    Ahhh that makes some sense, thank you.

Similar Threads

  1. Optimizing DIV
    By skimask in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 22nd September 2008, 04:58
  2. Modulus Question
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd March 2006, 01:53
  3. GPS waypoint distance in Km
    By Art in forum Code Examples
    Replies: 1
    Last Post: - 28th August 2005, 01:59
  4. Mathematics and remainder for PLL MC145158
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 24th August 2005, 04:32
  5. Retrieving Div32 Remainder
    By Darrel Taylor in forum Code Examples
    Replies: 4
    Last Post: - 20th August 2003, 03:53

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts