Author Topic: Is the Rem function out to lunch?!?!  (Read 2321 times)

0 Members and 1 Guest are viewing this topic.

zoltan

  • Guest
Is the Rem function out to lunch?!?!
« 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!

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Is the Rem function out to lunch?!?!
« Reply #1 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)))
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

zoltan

  • Guest
Re: Is the Rem function out to lunch?!?!
« Reply #2 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
« Last Edit: March 24, 2006, 06:05:02 PM by zoltan »

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Is the Rem function out to lunch?!?!
« Reply #3 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"
R12 Dos - A2K