prakashreddy Posted April 28, 2013 Posted April 28, 2013 Rem is working different different or i may understood wrong (rem 1262.8 180.4) 180.4 (rem 4.2 2.1) 0.0 Can any clear me Quote
Stefan BMR Posted April 28, 2013 Posted April 28, 2013 Divides the first number by the second, and returns the remainder For any A and B, A=n*B+R, where n is the largest possible integer and R is the remainder.In your sample 1262.8 = 7 * 180.4 + 0 and it should return 0.0 The trouble with reals is that they are always truncated, so what you think is 180.4 is in fact 180.399999999.... _$ (rtos (rem 1262.8 180.4) 2 16) "180.3999999999999" _$ Quote
Lee Mac Posted April 28, 2013 Posted April 28, 2013 As Stefan has correctly pointed out, given that reals (doubles) cannot be represented exactly (since this would require infinite memory), tolerances must be applied when working with reals. Hence, if you are looking to test for even divisibility of two reals, an alternative solution might be: (defun divisible-p ( n d / r ) (setq r (rem n d)) (or (equal r 0.0 1e- (equal r d 1e-) ) _$ (divisible-p 1262.8 180.4) T Here, a tolerance of 1e-8 (0.00000001) has been used. Quote
prakashreddy Posted April 28, 2013 Author Posted April 28, 2013 (/= 0 (rem (* 100 (- 1443.60 180.80)) (* 100 180.4))) Is there any other way to resolve it... Quote
prakashreddy Posted April 28, 2013 Author Posted April 28, 2013 Thanks Mr Stefan & Mr Lee for your information. Quote
Lee Mac Posted April 28, 2013 Posted April 28, 2013 Thanks Mr Stefan & Mr Lee for your information. You're very welcome. On this topic, you may want to read this article. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.