On Thu, Jun 18, 2009 at 9:08 AM, Kumar Appaiah wrote: > > Sorry, I clicked sent before completing the mail!
OK, there really is a keyboard fault here. Sorry about this! > On Thu, Jun 18, 2009 at 9:07 AM, Kumar Appaiah <[email protected]> > wrote: > > > > On Thu, Jun 18, 2009 at 9:03 AM, Mayank wrote: > > > I'm sorry if this question has been asked before but I couldn't find > > > any appropriate answer elsewhere and hence this post. Today while doing > > > some > > > calculation using bc I found a very peculiar thing. I was performing an > > > operation -2 % -3 and the software reported the answer as -2. Now -2 > -3 > > > and if I remember correctly then in divison operation the remainder is > > > less > > > than the divisor. So how come in this case the answer is not coming > > > properly. Is it a software flaw or there is some mistake in my > > > understanding > > > of the division operation ? > > > > From the bc man page: > > > > "expr % expr > > The result of the expression is the "remainder" and it > > is computed in the following way. To compute a%b, first a/b is > > computed to scale digits. That result is used to compute a-(a/b)*b to > > the scale of the maximum of scale+scale(b) and scale(a). If scale is > > set to zero and both expressions are integers this expression is the > > integer remainder function." > > Now, the default "scale" in bc is 0, which takes all fractions to the integer preceding them. e.g. 15/8 evaluates to 1. Now, try your expression. -2/-3 is 0, then -2 - (-2/-3)*-3 is -2. So that is what you get, right? Now, it isn't the remainder function, but then, it does what is advertised, I guess. HTH, and sorry for 3 mails. :-( Kumar -- Kumar -- http://mm.glug-bom.org/mailman/listinfo/linuxers

