Results 1 to 7 of 7

Math Help - Modulo and division on representation: amount * limit + offset.

  1. #1
    Newbie
    Joined
    Apr 2013
    From
    Earth
    Posts
    18

    Exclamation Modulo and division on representation: amount * limit + offset.

    Representation: amount * limit + offset, where the result of amount * limit + offset cannot be directly accessed.

    Code:
    (((amount * (limit % radix)) % radix) + (offset % radix)) % radix
    is how to do modulo on representation amount * limit + offset without directly accessing amount * limit + offset.

    amount is the amount of limit you have, offset is a number >= 0 and <= limit. Offset, amount and limit are whole numbers.

    Division i cannot figure out, please help me(not to just dump everything on you, but i am unable to figure it out).
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor
    Joined
    Sep 2012
    From
    Australia
    Posts
    4,169
    Thanks
    765

    Re: Modulo and division on representation: amount * limit + offset.

    Hey indieExe.

    Can you explain in plain word what you want to find (like an equation), what you are given (and the format its in) and what you can use (and the format its in)?
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Apr 2013
    From
    Earth
    Posts
    18

    Re: Modulo and division on representation: amount * limit + offset.

    The division needs to be done in two separate parts.

    1. Calculate new offset.
    2. Calculate new amount.
    (The order doesn't really matter, i think).

    (considering these are all positive real numbers)
    new_amount = ((n/limit) * amount) + ((offset/n)/limit). This would give the amount n would repeat in limit * amount + offset.

    new_offset = (float new_amount - int new_amount) * ???

    new_amount = int new_amount.

    I think this would be correct. Now the remnants of new_amount is the new_offset.
    But how do i retrieve the new_offset?

    (I don't really know what you mean by format, and does plain word mean in this context?)
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Newbie
    Joined
    Apr 2013
    From
    Earth
    Posts
    18

    Re: Modulo and division on representation: amount * limit + offset.

    Plain word:
    How do one calculate the division: (limit * amount + offset) / n, when amount is the amount of limit one currently have, offset is a number >= 0 and <= limit,
    and when one cannot obtain the result of (limit * amount + offset) / n directly because one can only operate on a number <= limit.

    The result of the division should be put into in the format: new_amount * limit + new_offset.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Apr 2013
    From
    Earth
    Posts
    18

    Re: Modulo and division on representation: amount * limit + offset.

    Did you want to help me or not?
    Follow Math Help Forum on Facebook and Google+

  6. #6
    MHF Contributor
    Joined
    Sep 2012
    From
    Australia
    Posts
    4,169
    Thanks
    765

    Re: Modulo and division on representation: amount * limit + offset.

    So if you have a number N and want to get it in form (limit,amount,offset) then calculate

    integer(N/limit) for amount. Take this value and calculate
    N - amount*limit for offset.

    In C++ this is basically offset = N%limit and amount = (N - offset)/limit.
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Super Member
    Joined
    Dec 2012
    From
    Athens, OH, USA
    Posts
    712
    Thanks
    298

    Re: Modulo and division on representation: amount * limit + offset.

    Hi,
    Let me see if I understand your question. You want to do integer arithmetic and for ints limit, amount and n you want to compute (amount*limit)/n and (amount*limit)%n even when the product amount*limit results in overflow. That is, if max is the largest possible int (in C INT_MAX or Java Integer.MAX_INT) and amount*limit exceeds max, you still want the correct int values.

    In a high level language, at least the ones that I know, there is no indication of overflow. So the only solution is to do multi-precision arithmetic. I've kind of lost track of the standard C++ library, but I know in Java the class BigInteger will do the desired arithmetic. You just have to switch from ints to BigInteger instances. Alternatively, you can write your own multi-precision routines specifically to handle the problem as I understand it. I've written my own big integers in both C++ and Java. It turns out that the hardest thing to do is division and remaindering for big integers. So, my advice is to use some "canned" multi-precision routines if you can.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. modulo division with negative power ?
    Posted in the Number Theory Forum
    Replies: 0
    Last Post: January 5th 2012, 04:42 AM
  2. Amount of quadratic residues and nonresidues modulo p
    Posted in the Number Theory Forum
    Replies: 1
    Last Post: July 23rd 2011, 10:47 PM
  3. Limit of a power series representation
    Posted in the Calculus Forum
    Replies: 10
    Last Post: May 17th 2010, 09:22 PM
  4. Gamma Function- Limit/ Product Representation-
    Posted in the Calculus Forum
    Replies: 6
    Last Post: May 8th 2010, 10:19 PM
  5. Division table modulo 5
    Posted in the Number Theory Forum
    Replies: 1
    Last Post: August 2nd 2009, 06:28 AM

Search Tags


/mathhelpforum @mathhelpforum