Jump to content

Recommended Posts

Posted

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

Posted

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"
_$ 

Posted

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.

Posted

(/= 0 (rem (* 100 (- 1443.60 180.80)) (* 100 180.4)))

 

 

Is there any other way to resolve it...

Posted

Thanks Mr Stefan & Mr Lee for your information.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...