Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: How can we know that value is real of Integer

  1. #1
    Active Member
    Join Date
    2005-02
    Posts
    95
    Login to Give a bone
    0

    Default How can we know that value is real of Integer

    I have a one problem. I can extract data from dimensions, and there is DIMRND set 0.5.

    Now I have a lots of dimension text in my list. like. 110.0 , 1100.5 , 637.5, 3137.0
    I had rounded up at the time of taking dimensions. now I called up in lisp as

    (rtos dmval1 2 1). now I want to write above value in the drawing but as a
    110.0 to 110.0
    1100.5 to 1100.5
    637.5 to 637.5
    3137.0 to 3137

    above mentioned list can be a min. 6 to max. 1250 or more.

    Now my question is how can we determine 1100 is a intger and 637.5 is a real value

    can anyone give me help to out.

    Thanks,
    Avinash

  2. #2
    100 Club
    Join Date
    2005-09
    Posts
    111
    Login to Give a bone
    0

    Default Re: How can we know that value is real of Integer

    Quote Originally Posted by avinash00002002 View Post
    I have a one problem. I can extract data from dimensions, and there is DIMRND set 0.5.

    Now I have a lots of dimension text in my list. like. 110.0 , 1100.5 , 637.5, 3137.0
    I had rounded up at the time of taking dimensions. now I called up in lisp as

    (rtos dmval1 2 1). now I want to write above value in the drawing but as a
    110.0 to 110.0
    1100.5 to 1100.5
    637.5 to 637.5
    3137.0 to 3137

    above mentioned list can be a min. 6 to max. 1250 or more.

    Now my question is how can we determine 1100 is a intger and 637.5 is a real value

    can anyone give me help to out.

    Thanks,
    Avinash
    Dear Avinash,

    See
    Code:
    (defun Int_Or_Real0(X)
    (if (eq (type x) 'INT) (print "It is a Integer"))
    (if (eq (type x) 'REAL) (print "It is a Real"))
    (princ)
    )
    Code:
    (Int_Or_Real0 1000); gives "Type is a Integer"
    (Int_Or_Real0 1000.0); gives "Type is a Real"
    Code:
    (defun Int_Or_Real(X)
    (if (/= (- x (fix x)) 0) (print "It is not a Integer")
    (print "Type could be a Integer"))
    )
    Code:
    (Int_Or_Real 1000); gives "Type could be a Integer"
    (Int_Or_Real 1000.0); gives "Type could be a Integer"
    (Int_Or_Real 1000.5); gives "It is not a Integer"
    Regards HofCAD

  3. #3
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: How can we know that value is real of Integer

    The value you are going to get from the dimension will always be a real number. If you want to know if it can be represented as an integer, then one way is to get convert it to a string, and check to see if the numbers after the decimal are all zeros. Or you could see if the the integer value matches the real value, but I would go with the first option.

  4. #4
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: How can we know that value is real of Integer

    Quote Originally Posted by T.Willey View Post
    . . .convert it to a string, and check to see if the numbers after the decimal are all zeros. . .
    That is not secure, often AutoCAD calculate numbers like
    (zerop (- (fix 1230.0000000001 ) 1230.0000000001 )) --> nil
    but truncated it may work
    (zerop (- (fix 1230.000000 ) 1230.000000 )) --> T
    (zerop (- (fix 1230.100254 ) 1230.100254 )) --> nil

    : ) Happy Computing !

    kennet

  5. #5
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: How can we know that value is real of Integer

    Quote Originally Posted by kennet.sjoberg View Post
    That is not secure, often AutoCAD calculate numbers like
    (zerop (- (fix 1230.0000000001 ) 1230.0000000001 )) --> nil
    but truncated it may work
    (zerop (- (fix 1230.000000 ) 1230.000000 )) --> T
    (zerop (- (fix 1230.100254 ) 1230.100254 )) --> nil

    : ) Happy Computing !

    kennet
    You're example is correct, but it is not what I said in the quote you took. You can take a real and convert it to a string with 16 decimal places and check them all if you wanted to, but that isn't what the OP wanted either. For what the OP wants I stand by what I said.

  6. #6
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: How can we know that value is real of Integer

    Quote Originally Posted by T.Willey View Post
    The value you are going to get from the dimension will always be a real number. If you want to know if it can be represented as an integer, then one way is to get convert it to a string, and check to see if the numbers after the decimal are all zeros. Or you could see if the the integer value matches the real value, but I would go with the first option.
    I would not rely on string conversions.
    Code:
    (defun IsInteger  (x)
     (cond ((= (type x) 'INT))
           ((equal (- x (fix x)) 0.0 1e-15))))
    Note that you can change the precision test (1e-15) but any greater precision than that value is likely overkill.
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

  7. #7
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: How can we know that value is real of Integer

    Quote Originally Posted by RobertB View Post
    I would not rely on string conversions.
    Code:
    (defun IsInteger  (x)
     (cond ((= (type x) 'INT))
           ((equal (- x (fix x)) 0.0 1e-15))))
    Note that you can change the precision test (1e-15) but any greater precision than that value is likely overkill.
    That is a good way. Thanks Robert.

  8. #8
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: How can we know that value is real of Integer

    Quote Originally Posted by T.Willey View Post
    You're example is correct, but it is not what I said in the quote you took. You can take a real and convert it to a string with 16 decimal places and check them all if you wanted to, but that isn't what the OP wanted either. For what the OP wants I stand by what I said.
    But I do not agree

    (rtos 43.0 2 16 ) --> "42.99999999999999"
    (rtos 81.0 2 16 ) --> "80.99999999999999"
    (rtos 86.0 2 16 ) --> "85.99999999999999"
    (rtos 91.0 2 16 ) --> "90.99999999999999"


    : ) Happy Computing !

    kennet

  9. #9
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: How can we know that value is real of Integer

    I must say again that this task is tricky

    Roberts function will also sometimes return in nil
    Code:
    (IsInteger (atof (rtos 43.0 2 16 )) ) ; --> nil
    (IsInteger (atof (rtos 81.0 2 16 )) ) ; --> nil
    (IsInteger (atof (rtos 86.0 2 16 )) ) ; --> nil
    (IsInteger (atof (rtos 91.0 2 16 )) ) ; --> nil
    
    (IsInteger (atof (rtos 15.0 2 16 )) ) ; --> T

    : ) Happy Computing !

    kennet

  10. #10
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: How can we know that value is real of Integer

    Quote Originally Posted by kennet.sjoberg View Post
    I must say again that this task is tricky

    Roberts function will also sometimes return in nil
    Code:
    (IsInteger (atof (rtos 43.0 2 16 )) ) ; --> nil
    (IsInteger (atof (rtos 81.0 2 16 )) ) ; --> nil
    (IsInteger (atof (rtos 86.0 2 16 )) ) ; --> nil
    (IsInteger (atof (rtos 91.0 2 16 )) ) ; --> nil
    
    (IsInteger (atof (rtos 15.0 2 16 )) ) ; --> T
    Why, in all that's decent and fair, are you converting a real to a string and then back to a real?! You are simply forcing floating-point errors. Which is why I advised against string conversions.
    Code:
    _$ (IsInteger 43.0)
    T
    _$ (IsInteger 81.0)
    T
    _$ (IsInteger 86.0)
    T
    _$ (IsInteger 91.0)
    T
    _$ (IsInteger 15.0)
    T       
    _$ (rtos 43.0 2 16)
    "42.99999999999999"
    _$ (rtos 81.0 2 16)
    "80.99999999999999"
    _$ (rtos 86.0 2 16)
    "85.99999999999999"
    _$ (rtos 91.0 2 16)
    "90.99999999999999"
    _$ (rtos 15.0 2 16)
    "15.00000000000000"
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 0
    Last Post: 2014-12-01, 05:02 AM
  2. Real or Integer value
    By avinash patil in forum VBA/COM Interop
    Replies: 4
    Last Post: 2011-09-14, 10:49 AM
  3. Select case by integer - Restrict integer value to one
    By CADfunk MC in forum VBA/COM Interop
    Replies: 4
    Last Post: 2010-05-24, 08:02 AM
  4. Using 'if" to test for a real or integer
    By Rick Stanich in forum AutoLISP
    Replies: 14
    Last Post: 2009-07-26, 08:12 PM
  5. Replies: 8
    Last Post: 2006-10-12, 12:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •