Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

Integer Divide in 'C'

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Integer Divide in 'C'

    I thought the forward slash '/' was integer divide in C. ????? bobh

  • #2
    Integer Divide in 'C'

    It depends on the operands. It's integer divide if you use integer operands.
     #include  int main(void) { int i1 = 3; int i2 = 2; double d1 = 3; double d2 = 2; double d; d = i1 / i2; // d == 1 d = d1 / d2; // d == 1.5 } 
    Barbara Morris

    Comment


    • #3
      Integer Divide in 'C'

      What about % ; I had thought that this returned the equivalent of trunc(a/b). I'm converting a bunch of old DEC 'C' routines to REXX and I stumbled on that one... a = (1 - 14)/12 If a is int or long int; but evidently not in the 'C' that I stumbled onto. WOW!!!!! thnx, bobh

      Comment


      • #4
        Integer Divide in 'C'

        Bob, I could be wrong, but I think that the "%" sign deals with remainders resulting from division. It's sort of like MVR in RPG, or GIVING REMAINDER IN Cobol. I know that I've used "%" in C. I'm pretty it was with remainder and date routines.

        Comment


        • #5
          Integer Divide in 'C'

          I'm not sure about in C, but in BASIC or VB, the integer divide is the backslash character (''), so: A / B is a regular divide. A B is integer divide. ==Scott==

          Comment


          • #6
            Integer Divide in 'C'

            The problem turned out to be the Floor function and the % operator which is not the same as a REXX // function. Got the 'C' train back on track, with apologies to the DUKE. The particular stuff giving problems was not from DEC but OS/2, another IBM step-child. thnx for your help... bobh

            Comment

            Working...
            X