See the top rated post in this thread. Click here

Results 1 to 5 of 5

Thread: Question on Read function

  1. #1
    Member
    Join Date
    2019-01
    Posts
    3
    Login to Give a bone
    1

    Default Question on Read function

    I recently ran across this, I created a work around but am wondering if someone can provide an explanation.
    All 10 character strings:

    Code:
    Command: (type(read "2146000000"))
    INT
    
    Command: (type(read "2147000000"))
    INT
    
    Command: (type(read "2148000000"))
    REAL

    The code I was working on was expecting an INT value but failed when we added 10 digit values to some of our data.

    Thanks.

  2. #2
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Question on Read function

    Hi,

    You can try this function to work around that function's issue.
    Code:
    (defun type_ (str)  (if (numberp (read str))
        (if (or (vl-string-search "." str)
                (vl-string-search "," str)
            )
          'REAL 'INT)
      )
    )

  3. #3
    Member
    Join Date
    2019-01
    Posts
    3
    Login to Give a bone
    0

    Default Re: Question on Read function

    Quote Originally Posted by Tharwat View Post
    Hi,

    You can try this function to work around that function's issue.
    Code:
    (defun type_ (str)  (if (numberp (read str))
        (if (or (vl-string-search "." str)
                (vl-string-search "," str)
            )
          'REAL 'INT)
      )
    )
    Thanks for the reply.
    I also noticed similar odd behavior with the ATOI function.
    Apparently there's some limitation as to the size of the number involved.

    Command: (atoi "2146000000")
    2146000000

    Command: (atoi "2147000000")
    2147000000

    Command: (atoi "2148000000")
    2147483647

    Command: (atoi "8452657842")
    2147483647

  4. #4
    Woo! Hoo! my 1st post
    Join Date
    2006-11
    Posts
    1
    Login to Give a bone
    1

    Default Re: Question on Read function

    Coucou, Hello

    it is not the function "read" that is in question...

    it's because you've reached the limit of integer numbers

    AutoLISP integers are 32-bit signed numbers with values ranging from +2,147,483,647 to -2,147,483,648.
    Some functions through, only accept 16-bit numbers ranging from +32767 to -32678.
    When you explicitly use an integer, that value is known as a constant. Numbers such as 2, -56, and 1,200,196 are valid integers.
    If you enter a number that is greater than the maximum integer allowed (resulting in integer overflow), AutoLISP converts the integer to a real number.

    amicalement, regards

  5. #5
    Member
    Join Date
    2019-01
    Posts
    3
    Login to Give a bone
    0

    Default Re: Question on Read function

    Thanks for the replies, and the reminder that there is a maximum integer limit.
    This also explains similar behavior with using the ATOI function.

Similar Threads

  1. 2010LT function question
    By dccg in forum AutoCAD LT - General
    Replies: 2
    Last Post: 2010-01-18, 02:51 PM
  2. question on making cui and standards read only
    By nkennelly in forum AutoCAD CUI Menus
    Replies: 1
    Last Post: 2010-01-15, 07:17 PM
  3. Question about the TEXT function
    By cris_scotti in forum Revit Architecture - General
    Replies: 2
    Last Post: 2008-08-27, 06:12 PM
  4. Time Function question
    By drafting700 in forum ACA General
    Replies: 4
    Last Post: 2006-07-20, 08:31 AM
  5. Read-Only Question
    By Rico in forum AutoCAD LT - General
    Replies: 24
    Last Post: 2005-11-09, 04:12 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
  •