Can we use % operator for double type?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cworld
    New Member
    • Jan 2007
    • 15

    Can we use % operator for double type?

    Hello dear
    I am writing a program for calculator. I am getting error when I use % operator for remainder because I have used push-pop command for double type. So can i use % for double type? or some other operator ? Suggest me Plz!!
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    Unfortunately, the modulus division operator (%) only works for integer values. You could write your own, however, if you could find out an algorithm for manually calculating the remainder.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by cworld
      Hello dear
      I am writing a program for calculator. I am getting error when I use % operator for remainder because I have used push-pop command for double type. So can i use % for double type? or some other operator ? Suggest me Plz!!
      Sounds like something is not proper here to me. Either the values should not be double in the first place or you should not be trying to mod them. Are you sure the design is correct.

      Comment

      • cworld
        New Member
        • Jan 2007
        • 15

        #4
        Originally posted by Ganon11
        Unfortunately, the modulus division operator (%) only works for integer values. You could write your own, however, if you could find out an algorithm for manually calculating the remainder.
        Thankyou very much Ganon11,
        I was just trying one ther command for modulus and I got my problem solved. This is for the others facing the problem, we can use fmod(double x, double y) command i.e. fmod command which is available in <math.h>
        Thankyou for ur reply.

        Comment

        • cworld
          New Member
          • Jan 2007
          • 15

          #5
          Originally posted by r035198x
          Sounds like something is not proper here to me. Either the values should not be double in the first place or you should not be trying to mod them. Are you sure the design is correct.
          Thankyou for ur response,
          actually i was facing this problem for double type since i am using push and pop command for double type everywhere in my program . Now prob is solved i can use fmod command for this
          Thankyou

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by cworld
            Thankyou for ur response,
            actually i was facing this problem for double type since i am using push and pop command for double type everywhere in my program . Now prob is solved i can use fmod command for this
            Thankyou
            Thank you. I didn't know about fmod and was beginning to try to write my own mod for doubles. Guess there is no more need for that now.

            Comment

            • Ganon11
              Recognized Expert Specialist
              • Oct 2006
              • 3651

              #7
              Yes, that's something cool I didn't know about. Awesome!

              Comment

              Working...