TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: zoltan on March 24, 2006, 04:51:13 PM

Title: Is the Rem function out to lunch?!?!
Post by: zoltan on March 24, 2006, 04:51:13 PM
...or am I reading this wrong?

_$ (rem 1.0 0.1)
0.1
_$ (/ 1.0 0.1)
10.0

 :ugly: I'm so confused!
Title: Re: Is the Rem function out to lunch?!?!
Post by: MP on March 24, 2006, 05:01:48 PM
Looks like a bug to me. You may have to normalize the data so the divisor is an integer.

i.e. <oversimplied for simplicity/clarity> (apply 'rem (mapcar '(lambda (x) (* 10 x)) '(1.0 0.1)))
Title: Re: Is the Rem function out to lunch?!?!
Post by: zoltan on March 24, 2006, 05:56:19 PM
If you change the input to an integer, then it will output an integer.

hmm...

Code: [Select]
(Defun NewRem ( NUM1 NUM2 )
 (/ (Rem (* NUM1 10.0) (* NUM2 10.0)) 10.0 )
)

is this going to solve it?

_$ (rem 0.1 0.01)
3.46945e-018

_$ (/ 1.0 0.01)
100.0

_$ (NewRem 1.0 0.1)
0.0

_$ (NewRem 0.1 0.01)
0.01

This is not looking too good.

Let's try this:
Code: [Select]
(Defun MyRem ( NUM1 NUM2 )
 (- NUM1 (* NUM2 (Fix (/ NUM1 NUM2))) )
)


hmm..

edit: oops
Title: Re: Is the Rem function out to lunch?!?!
Post by: David Bethel on March 25, 2006, 09:26:07 AM
It's back to the real number storage problem.  For some reason (rem) rounds 1.0 down just a little bit.  -David

Code: [Select]
Command: (rtos (rem 1.0 0.1) 2 16)
"0.1000000000000000"

Command: (rtos (rem (+ 1 1e-15) 0.1) 2 16)
"0.0000000000000011"

Command: (rtos (rem (+ 1 1e-16) 0.1) 2 16)
"0.1000000000000000"