Integer division (quotient)

Issue #62 closed
Former user created an issue

Originally reported on Google Code with ID 62

In the same way as the MOD operation described in Issue 16, we should
provide the DIV operation, returning the integer division.

If someone finds a better name, please do propose :)

Reported by helder.pereira.correia on 2007-07-04 22:01:11

Comments (10)

  1. Former user Account Deleted

    ``` DIV and MOD are both operations that have some pitfalls lurking around. So one should be careful when implementing them. 1. Both operations have the connotation of being exact. While this is easy to achieve with integers, floating point arithmetic is not so obliging. Unfortunately, DIV and MOD are numerically unstable and susceptible to rounding errors. Compare, for instance, 1 DIV 1 == 1 and ((1/3)*3) DIV 1 == ? Some calculators will evaluate 0 in the latter case, others 1.

    2. Both operations can be very time consuming. An operation like 10^1000 mod 10^-1000 requires 2000 full-scale division steps -- the slow-down may effect the on-the-fly evaluation already. OK, with the current number range from 10^-70 to 10^150, I do not expect much trouble, but the floatnum engine e.g. allows much greater numbers, up to the point where these operations cannot be executed any more.

    3. With negative operands both operations are ambiguous. Does 5 div -2 mean FLOOR(-5/2) == -3 or TRUNC(-5/2) == -2? Both definitions are in wide-spread use.

    I suggest to postpone their implementation, until you have a clearer view of whether SpeedCrunch gets a special integer mode or not. (This question will rise anyway, the moment you want logical operations). If you decide to have an integer mode, maybe your question will be gone, because the operator / means DIV in integer mode and ordinary division in floating point mode, the same way the C operator is defined. And not having DIV in floating point mode does not hurt much IMHO, because in the rare case you should really need it, FLOOR(a/b) does the same.

    Wolf Lammen ```

    Reported by `ookami1@gmx.de` on 2007-07-05 07:56:57

  2. Former user Account Deleted

    Reported by `helder.pereira.correia` on 2007-11-03 19:40:38 - Labels added: Milestone-0.10 - Labels removed: Milestone-0.9

  3. Former user Account Deleted

    ``` available in trunk as 'idiv' function. See doc/logic-unit.pdf for details ```

    Reported by `wolf.lammen` on 2007-11-20 18:31:31

  4. Former user Account Deleted

    ``` See issue #90. ```

    Reported by `helder.pereira.correia` on 2007-11-20 21:42:59 - Status changed: `Started`

  5. Former user Account Deleted

    Reported by `helder.pereira.correia` on 2008-03-28 22:25:25 - Labels added: Milestone-0.11 - Labels removed: Milestone-0.10

  6. Former user Account Deleted

    Reported by `helder.pereira.correia` on 2008-07-19 18:23:46 - Labels removed: Milestone-0.11

  7. Former user Account Deleted

    ``` Extended the functionality introduced by Wolf by adding the '\' operator, widely used

    by mathematicians and math software. Implemented in commit 1bbd97b774da2077e60922534d7fff51fe411a59 ```

    Reported by `helder.pereira.correia` on 2010-03-13 04:40:09 - Status changed: `Fixed` - Labels added: OpSys-All, Milestone-0.11, Component-Logic, Usability

  8. Log in to comment