Multiplying Large Numbers

Multiplying Large Numbers

Anonymous
Not applicable
1,263 Views
4 Replies
Message 1 of 5

Multiplying Large Numbers

Anonymous
Not applicable

Hi, Dear 

I have many large number to multiply it is giving error in big numbers but it is ok for smaller numbers.

thanks

 

(defun c:Mutxt (/ ans flag)
  (setq flag t)
  (setvar "cmdecho" 0)
  (setvar "osmode" 0)
   (setq ht (getint "\nEnter Universal Height"))
 
  (while flag
    (initget "1 2 3 4 5 6 7 8 9 10")
    (setq ans (entsel "\nmake your selection[2/3/4/5/6/7/8/9/10]<exit>:"))
    (cond ((= ans nil)
    (setq flag nil)
    (prompt "\nyou didn't select an object, or you did press spacebar or enter, to exit...")
   )
          ((= 'list (type ans))
    (prompt "\nyou did select an object...")
   )
  ((= "2" ans)
    ;(prompt "\nyou did enter Beta...")
    (setq 1st (atoi (cdr (assoc 1 (entget (car (entsel "\nSelect the First Text")))))))
    (setq 2nd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Second Text")))))))
    (setq addd (* 1st 2nd))
    (command "text" Pause ht "0" addd "")
     )

          ((= "3" ans)
    ;(prompt "\nyou did enter Beta...")
           (setq 1st (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the First Text")))))))
    (setq 2nd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Second Text")))))))
    (setq 3rd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Third Text")))))))
    (setq addd (* 1st 2nd 3rd))
    (command "text" Pause ht "0" addd "")
    )

   ((= "4" ans)
    ;(prompt "\nyou did enter Beta...")
           (setq 1st (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the First Text")))))))
    (setq 2nd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Second Text")))))))
    (setq 3rd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Third Text")))))))
    (setq 4th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fourth Text")))))))
    (setq addd (* 1st 2nd 3rd 4th))
    (command "text" Pause ht "0" addd "")
    )
         ((= "5" ans)
    ;(prompt "\nyou did enter Beta...")
           (setq 1st (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the First Text")))))))
    (setq 2nd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Second Text")))))))
    (setq 3rd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Third Text")))))))
    (setq 4th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fourth Text")))))))
    (setq 5th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fifth Text")))))))
    (setq addd (* 1st 2nd 3rd 4th 5th))
    (command "text" Pause ht "0" addd "")
    )
         ((= "6" ans)
    ;(prompt "\nyou did enter Beta...")
           (setq 1st (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the First Text")))))))
    (setq 2nd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Second Text")))))))
    (setq 3rd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Third Text")))))))
    (setq 4th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fourth Text")))))))
    (setq 5th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fifth Text")))))))
    (setq 6th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the sixth Text")))))))
    (setq addd (* 1st 2nd 3rd 4th 5th 6th))
    (command "text" Pause ht "0" addd "")
    )
   ((= "7" ans)
    ;(prompt "\nyou did enter Beta...")
           (setq 1st (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the First Text")))))))
    (setq 2nd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Second Text")))))))
    (setq 3rd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Third Text")))))))
    (setq 4th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fourth Text")))))))
    (setq 5th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fifth Text")))))))
    (setq 6th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the sixth Text")))))))
    (setq 7th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the seventh Text")))))))
    (setq addd (* 1st 2nd 3rd 4th 5th 6th 7th))
    (command "text" Pause ht "0" addd "")
    )
         ((= "8" ans)
    ;(prompt "\nyou did enter Beta...")
           (setq 1st (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the First Text")))))))
    (setq 2nd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Second Text")))))))
    (setq 3rd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Third Text")))))))
    (setq 4th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fourth Text")))))))
    (setq 5th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fifth Text")))))))
    (setq 6th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the sixth Text")))))))
    (setq 7th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the seventh Text")))))))
    (setq 8th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Eighth Text")))))))
    (setq addd (* 1st 2nd 3rd 4th 5th 6th 7th 8th))
    (command "text" Pause ht "0" addd "")
    )
         ((= "9" ans)
    ;(prompt "\nyou did enter Beta...")
           (setq 1st (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the First Text")))))))
    (setq 2nd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Second Text")))))))
    (setq 3rd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Third Text")))))))
    (setq 4th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fourth Text")))))))
    (setq 5th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fifth Text")))))))
    (setq 6th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the sixth Text")))))))
    (setq 7th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the seventh Text")))))))
    (setq 8th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Eighth Text")))))))
    (setq 9th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Ninth Text")))))))
    (setq addd (* 1st 2nd 3rd 4th 5th 6th 7th 8th 9th))
    (command "text" Pause ht "0" addd "")
    )
         ((= "10" ans)
    ;(prompt "\nyou did enter Beta...")
           (setq 1st (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the First Text")))))))
    (setq 2nd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Second Text")))))))
    (setq 3rd (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Third Text")))))))
    (setq 4th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fourth Text")))))))
    (setq 5th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Fifth Text")))))))
    (setq 6th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the sixth Text")))))))
    (setq 7th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the seventh Text")))))))
    (setq 8th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Eighth Text")))))))
    (setq 9th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the Ninth Text")))))))
    (setq 10th (atoi (cdr (assoc 1 (entget(car (entsel "\nSelect the tenth Text")))))))
    (setq addd (* 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th))
    (command "text" Pause ht "0" addd "")
  
    )

    );; cond
  );; while
  (princ)
)

 

0 Likes
1,264 Views
4 Replies
Replies (4)
Message 2 of 5

dbroad
Mentor
Mentor

If you want large numbers, don't use integers. There is a limit to how big integers can get.  Instead, use floating point numbers.  ATOI returns an integer. You can automatically promote the numbers to real (floating point numbers ) if you also multiply by 1.0.

 

Example

 

(* 1.0 1st 2nd)

 

or 

 

(* 1st (float 2nd))

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 3 of 5

Anonymous
Not applicable

Thanks Sir,

what about the value now it is coming something like this 

5.975308620246914E+016

 

0 Likes
Message 4 of 5

dbroad
Mentor
Mentor

What do you want it to look like?  When numbers exceed a certain value, it's easier to use scientific notation.  What is the purpose of these experiments?

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 5 of 5

DannyNL
Advisor
Advisor

I've modified my code that I put in your previous post about adding numbers (didn't see this one yet) and the code below will let you choose between adding or multiplying, but without the same limitation of your code as described in your other post.

 

As soon as a number gets real large AutoCAD will automatically switch to scientific notation. I'm not sure if this is something you can prevent.

 

(defun c:SMTxt (/ SM_Selection SM_Total SM_Count SM_Operator SM_Action)
   (setq SM_Selection (ssget '((0 . "TEXT"))))
   (if
      SM_Selection
      (progn
         (initget "Sum Multiply Exit")
         (setq SM_Action (getkword "\nOption for numbers [Sum/Multiply]: "))
         (if
            SM_Action
            (progn               
               (if
                  (= SM_Action "Sum")
                  (progn
                     (setq SM_Total 0)
                     (setq SM_Operator +)
                  )
                  (progn
                     (setq SM_Total 1)
                     (setq SM_Operator *)
                  )                  
               )
               (setq SM_Count 0)               
               (repeat (sslength SM_Selection)
                  (setq SM_Total (SM_Operator (atof (vla-get-TextString (vlax-ename->vla-object (ssname SM_Selection SM_Count)))) SM_Total))
                  (setq SM_Count (1+ SM_Count))
               )
               (if
                  (/= SM_Total 0)
                  (command "-TEXT" PAUSE PAUSE "0" (rtos SM_Total))
               )
            )
         )
      )
   )
   (princ)
)
0 Likes