Real to Int mathmatically (not fix)

Discussion in 'AutoCAD' started by Ken Alexander, May 6, 2004.

  1. I am not using this in lisp but I figured this would be the place to
    ask.

    Is there a math equation that will return an integer from an unknown
    real?

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, May 6, 2004
    #1
  2. Hi Ken,

    Do you mean:
    If UnknownObject is a real then return 1, if not return 0 ?
    or
    can you strip the decimal portion of the number leaving the digit part only
    ?
    or
    can you round the number to the nearest whole number ?

    The answer to all three is yes, but to allow readers to tell you how you
    need to clarify the question.


    Laurie Comerford
    CADApps
    www.cadapps.com.au
     
    Laurie Comerford, May 7, 2004
    #2
  3. Ken Alexander

    TCEBob Guest

    You have N=a.b (275.6833) and you want a or b (275 or 6833)?

    All programming languages (including vlisp) have at least one such
    function. What you want, I think, is an algebraic method. No can do,
    sorry. If you get into infinite series you can write a function that
    will limit to a or b. Alternatively, you can state "N mod a = b" and
    quiet any party.

    rs
     
    TCEBob, May 7, 2004
    #3
  4. Hi Laurie,

    Yes, I need to strip the decimal portion leaving an integer. This
    needs to be done with a math equation not a programming function.

    Thanks,

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, May 7, 2004
    #4
  5. Ken Alexander

    bob.at Guest

    Hi Ken,

    i would write it in this way:

    int (a) = a - (a mod 1)

    bob.at
     
    bob.at, May 7, 2004
    #5
  6. Ken Alexander

    Jürg Menzi Guest

    Ken

    (defun MyInt (Val)
    (fix (- Val (rem Val 1)))
    )

    Cheers
     
    Jürg Menzi, May 7, 2004
    #6
  7. Ken Alexander

    PF Guest

    (Hey,Ken! Long time since we passed notes!)

    Look for the Greatest Possible Integer... by definition, drops anything
    beyond the decimal.
    Since this is a real simple operation, someone must have done it in LISP by
    now.

    (I'd try Jurg's code... he has helped me a bit in the past... and that's not
    to say other contributions here don't work... just I haven't time to test
    and render opinion)

    regards!
     
    PF, May 7, 2004
    #7
  8. Bob,

    "Mod" was the ticket, Thanks a bunch.


    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, May 7, 2004
    #8
  9. Ken Alexander

    TCEBob Guest

    You are satisfied -- which is the bottom line.

    But, a little demurrer, "mod" is not an algebraic process, so the
    question "Is there a math equation that will return an integer from an
    unknown real?" is not really satisfied. In other words, x=3 mod 2 cannot
    be solved by algebraic means.

    rs
     
    TCEBob, May 7, 2004
    #9
  10. It looks as though I have not have worded my needs correctly.
    I've never heard of mod before today. So happens it fulfilled my
    needs for today. I'm sure there will be more later.

    Thanks for taking the time to respond to all.

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, May 7, 2004
    #10
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.