### Author Topic: WHY "FIX" FUNCTION ERROR ?  (Read 1960 times)

0 Members and 1 Guest are viewing this topic.

#### hunterxyz

• Guest
##### WHY "FIX" FUNCTION ERROR ?
« on: May 18, 2008, 09:14:37 AM »

(SETQ AA 10)
(SETQ BB 0.538516)
(SETQ CC (*(COS 1.9513026954188)BB))
(SETQ DD (ABS (* CC AA)))
_\$ 2.0

(SETQ EE (FIX DD))
_\$ 1

Asks fellow masters to explain thanks ~

#### gile

• Water Moccasin
• Posts: 2275
• Marseille, France
##### Re: WHY "FIX" FUNCTION ERROR ?
« Reply #1 on: May 18, 2008, 09:41:40 AM »
Hi,

May be a difference between the 5 decimal rounded displayed value (2.0) and the 16 decimal rounded value used in calculus (1.999998172232795)

Try (rtos DD 2 16)
Speaking English as a French Frog

#### DEVITG

• Bull Frog
• Posts: 463
##### Re: WHY "FIX" FUNCTION ERROR ?
« Reply #2 on: May 18, 2008, 01:11:35 PM »
(SETQ AA 10)
(SETQ BB 0.538516)
(SETQ CC (*(COS 1.9513026954188)BB))
(SETQ DD (ABS (* CC AA)))
_\$ 2.0
(setq dd\$ (rtos dd 2 15))
"1.999998172232795"
(setq dd# (atof dd\$))

;;;_\$ 2.0

(setq dd& (fix dd#))
;;;_\$ 1

(SETQ EE (FIX DD))
;;;_\$ 1
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

#### VovKa

• Swamp Rat
• Posts: 1352
• Ukraine
##### Re: WHY "FIX" FUNCTION ERROR ?
« Reply #3 on: May 18, 2008, 01:38:53 PM »
_\$ 1.99999
1.99999
_\$ 1.999999
2.0

visual lisp console uses some kind of rtos to print out the results. don't trust what you see

#### hunterxyz

• Guest
##### Re: WHY "FIX" FUNCTION ERROR ?
« Reply #4 on: May 18, 2008, 07:30:30 PM »
How to let SET EE = 2

#### Keith™

• Villiage Idiot
• Seagull
• Posts: 16867
• Superior Stupidity at its best
##### Re: WHY "FIX" FUNCTION ERROR ?
« Reply #5 on: May 18, 2008, 08:58:50 PM »
Code: [Select]
`(distof(rtos dd 2 0))`
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

#### gile

• Water Moccasin
• Posts: 2275
• Marseille, France
##### Re: WHY "FIX" FUNCTION ERROR ?
« Reply #6 on: May 19, 2008, 04:07:26 AM »
Hi,

Instead of fix function, you can use a rounding function, there're many around here, you can see this thread.

Here's mine (last release)

Code: [Select]
`(defun round (num prec)  (if (zerop (setq prec (abs prec)))    num    (if (minusp num)      (* prec (fix (- (/ num prec) 0.5)))      (* prec (fix (+ (/ num prec) 0.5)))    )  ))`
Using:
(round pi 0.01) -> 3.14
(round pi 1e-5) -> 3.14159
(round 5456.50 1) -> 5457
(round 5456.50 100.0) -> 5500.0

Note that if prec argument is an interger, the result will be an integer too.
Speaking English as a French Frog

#### CAB

• Global Moderator
• Seagull
• Posts: 10395
##### Re: WHY "FIX" FUNCTION ERROR ?
« Reply #7 on: May 19, 2008, 08:45:02 AM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

#### VovKa

• Swamp Rat
• Posts: 1352
• Ukraine
##### Re: WHY "FIX" FUNCTION ERROR ?
« Reply #8 on: May 19, 2008, 01:31:41 PM »
another one using vb data types
Code: [Select]
`(vl-load-com);;;range (Signed) of vlax-vbLong is −2147483648 to 2147483647;;;uses 'Round-to-even' method(defun Int (InReal)  (vlax-variant-value (vlax-make-variant InReal vlax-vbLong)))`
_\$ (Int 3.5)
4
_\$ (Int 4.5)
4

#### daron

• Guest
##### Re: WHY "FIX" FUNCTION ERROR ?
« Reply #9 on: May 19, 2008, 02:20:30 PM »
Hey Vlad, if 3.5 rounds to 4, should 4.5 round to 5 and maybe 4.49 round to 4?

#### VovKa

• Swamp Rat
• Posts: 1352
• Ukraine
##### Re: WHY "FIX" FUNCTION ERROR ?
« Reply #10 on: May 19, 2008, 05:15:39 PM »

#### Columbia

• Guest
##### Re: WHY "FIX" FUNCTION ERROR ?
« Reply #11 on: May 20, 2008, 08:05:06 AM »
Wow...you learn something new everyday.  I just learnt mine.  Does that mean I get to go home now?

#### CAB

• Global Moderator
• Seagull
• Posts: 10395
##### Re: WHY "FIX" FUNCTION ERROR ?
« Reply #12 on: May 20, 2008, 08:36:01 AM »