Jump to content

Recommended Posts

Posted

Hello

is there a better way for

(SETQ itno (ATOI (RTOS itno 2)))

i want a number that is in decimals points (real), to become zero decimals(intiger).rtos dose it to a string. but i need it as a real, for caculations and will this way round properly up and down?

and how would you check this.

As i would also like to be able to check if a sting is not at 0dp and fix this as a final step.

 

also

how do you get items 2 reconise another, tho one is not in capitals?

such as

(setq mp1 (getstring "\nSOME THING OR OTHER"))
(if (= mp1 "C")(RUN SOME THING)    

Where it will reconise "C" but not "c"

is their a way, so that i dont have to have capitals on?

(setq mp1 (getstring "\nSOME THING OR OTHER"
(cond (or (= mp1 "C") (= mp1 "c"))
(RUN SOME THING)    
)

Cheers

Flower

Posted

Flower,

 

Look into the (fix) and (strcase) functions.

 

(fix) rounds down only. It takes a bit more coding for a rounding function.

 

Compare the string case values of strings. -David

Posted

This may help somewhat:

 

;;* kdub:roundNearest (numVal roundTo displayPrecision)
;; Round a numeric positive number to the NEAREST 'rounded' number
;; and format to n digits
;; kwb@theSwamp 20070814
(defun kdub:roundNearest (numVal roundTo displayPrecision / remNum)
   (setq remNum (rem numVal roundTo))
   (rtos (if (>= (* 2 remNum) roundTo)
         (+ numVal (- roundTo remNum))
         (- numVal remNum)
     ) ;_  end IF
     2
     displayPrecision
   ) ;_  end RTOS
) ;_  end DEFUN

Posted

thanks david.

this is what i produced. is this what you had in mind?

(setq t0 (getreal "\nwhat number? :"))
(setq t1 (fix t0))
(setq t2 (- t0 t1))
(if (> t2 0.5)
 (setq t3 1)
 (setq t3 0)
)
(setq t4 (+ t1 t3))
(princ t4)
(princ)

 

lee, i carnt even work out how to make that code work.

i spend 10min just trying to work out how "rem" works

but dnt get their. maybe cause the coffee hasnt kicked in. or im a moron

thanks tho mate.

 

Flower

Posted

what is the differnce in most cases?

(correct \/)

real = 1.4

inti=1

 

and some time the 0.4 can be inportant, particually when working with masses. which is what im working on in my spare time.

tho most of the time i dont need the .0, but some time i do need it, if it wounds up.

and i find that you handle it the same??

or im in the habbit for them

Posted
what is the differnce in most cases?

(correct \/)

real = 1.4

inti=1

 

and some time the 0.4 can be inportant, particually when working with masses. which is what im working on in my spare time.

tho most of the time i dont need the .0, but some time i do need it, if it wounds up.

and i find that you handle it the same??

or im in the habbit for them

 

If you are going to request a REAL input and then round it to the nearest INTEGER, why not just request an INTEGER input? You are getting rid of the 0.4 either way?

Posted

Flowerrobot,

 

Here is the function that I use to round a number:

 

[color=Sienna];;;ROUND To 1[/color][b][color=BLACK]
[/color][/b][color=Sienna];;;ARG -> 'REAL
;;;RET -> 'INT[/color][b][color=BLACK]
([/color][/b]defun round1 [b][color=FUCHSIA]([/color][/b]r[b][color=FUCHSIA])[/color][/b]
[b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]<= 0.5 [b][color=MAROON]([/color][/b]abs [b][color=GREEN]([/color][/b]rem r 1[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
    [b][color=NAVY]([/color][/b]fix [b][color=MAROON]([/color][/b]1+ r[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
    [b][color=NAVY]([/color][/b]fix r[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

-David

Posted

Ahh i see the point you are making.

that code i put up was a example, (making it work for me)

and hence why it is all laid out simply.Then i reduce the steps.

i used this in my code

  (if (> (- (fix wt) wt) 0.5)
          (setq t5 (+ 1 (fix wt)))
          (setq t5 (fix wt))
          )
  (if (= t5 0)
  (setq t5 "-")
  )

I use "real" do calcs and stuff, then i use the rounding stuff at the final step where the .0 dosnt matter any more and only need it to the nearest kg.

 

Could one of you be so kind to explain "rem" i can not work the logic of it out.

the example in help shows

Command: [i](rem 42 12)[/i]
6

but 42/12 = 3.5, which means the remainder it 5?

Because i saw this one, and thought to use it, but couldnt get it 2 work.

 

Thanks for you help david.

and thanks lee for the critasim, its always helpful

Posted

Maybe this will help:

(rem 42 12)

3.5 * 12 = 42

0.5 * 12 = 6

42 - ( 3 * 12) = 6

or

(rem 3.4 1)

returns 0.4

the remainder of 3.4 divided by 1.0

Also, You might want to check, but I believe your code will produce an incorrect results when dealing with negative numbers. -David

Posted
Now that is a lot of brass air fittings there is just about every type

of air fitting that you could want. Wholesale prices too. I guess these could be used as small water pipe fitting also. I

used some of the parts to make my babington wvo bu

 

 

Excuse me?

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...