Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for multiply_3rdparty.bat

(view source code of multiply_3rdparty.bat as plain text)

  1. @ECHO OFF
  2. SETLOCAL ENABLEEXTENSIONS
  3. SETLOCAL ENABLEDELAYEDEXPANSION
  4. SETLOCAL
  5. SET _FIRST=%1
  6. SET _SECOND=%2
  7. CALL :MULTIPLY _FIRST _SECOND _ANSWER
  8. ECHO !_ANSWER!
  9. GOTO :END
  10.  
  11. :MULTIPLY
  12.    ::MULTIPLY NUMBERS LARGER THAN 32-BITS
  13.    ::SYNTAX: CALL MULTIPLY _VAR1 _VAR2 _VAR3
  14.    ::VER 1.2 - Fixed ending carry over bug - Thanks Justin
  15.    ::hieyeque1@gmail.com - drop me a note telling me
  16.    ::if this has helped you.  Sometimes I don't know if anyone uses my stuff
  17.    ::Its free for the world to use.
  18.    ::I retain the rights to it though, you may not copyright this
  19.    ::to prevent others from using it, you may however copyright works
  20.    ::as a whole that use this code.
  21.    ::Just don't try to stop others from using this through some legal means.
  22.    ::CopyRight Brian Williams 5/18/2009
  23.    :: _VAR1 = VARIABLE AGAINST WHICH WE SHALL COMPARE
  24.    :: _VAR2 = VARIABLE TO BE COMPARED
  25.    :: _VAR3 = VARIABLE WITH TRUE/FALSE RETURNED
  26.    SET _NUM1=!%1!
  27.    SET _NUM2=!%2!
  28.    SET _RESULT=%3
  29.    FOR /L %%A IN (1,1,2) DO (
  30.       FOR /L %%B IN (0,1,9) DO (
  31.          SET _NUM%%A=!_NUM%%A:%%B=%%B !
  32.          )
  33.       )
  34.    FOR %%A IN (!_NUM1!) DO SET /A _NUM1CNT+=1 & SET _!_NUM1CNT!_NUM1=%%A
  35.    FOR %%A IN (!_NUM2!) DO SET /A _NUM2CNT+=1 & SET _!_NUM2CNT!_NUM2=%%A
  36.    IF !_NUM1CNT! EQU 1 IF !_NUM2CNT! EQU 1 (
  37.       SET /A !_RESULT!=!_NUM1! * !_NUM2!
  38.       GOTO :EOF
  39.       )
  40.    FOR /L %%B IN (!_NUM2CNT!,-1,1) DO (
  41.       FOR /L %%A IN (!_NUM1CNT!,-1,1) DO (
  42.          SET /A _TMP=!_%%B_NUM2! * !_%%A_NUM1! !_PLUS! !_CO!
  43.          SET _CO=
  44.          SET _PLUS=
  45.          IF !_TMP! GTR 9 SET _CO=!_TMP:~0,1!& SET _TMP=!_TMP:~-1!& SET _PLUS=+
  46.          SET _NUM3_%%B=!_NUM3_%%B!!_SPC!!_TMP!
  47.          SET _SPC= 
  48.          SET _TMP=
  49.          )
  50.       IF DEFINED _CO SET _NUM3_%%B=!_NUM3_%%B! !_CO!& SET _CO=& SET _PLUS=
  51.       SET _NUM3_%%B=!_ZERO!!_NUM3_%%B!
  52.       SET _ZERO=0!_SPC1!!_ZERO!
  53.       SET _SPC1= 
  54.       FOR %%A IN (!_NUM3_%%B!) DO (
  55.         SET /A _CNT+=1
  56.         FOR %%C IN (!_CNT!) DO SET _NUM4_%%C=!_NUM4_%%C!%%A+
  57.         )
  58.       SET _CNT=
  59.       )
  60.    FOR /F %%A IN ('SET _NUM4') DO SET /A _COLCNT+=1
  61.    FOR /L %%A IN (1,1,!_COLCNT!) DO SET /A _NUM5_%%A=!_NUM4_%%A:~0,-1!
  62.    FOR /L %%A IN (1,1,!_COLCNT!) DO (
  63.       IF DEFINED _CO SET /A _NUM5_%%A=!_NUM5_%%A! + !_CO!
  64.       SET _CO=
  65.       IF !_NUM5_%%A! GTR 9 (
  66.          SET _CO=!_NUM5_%%A:~0,-1!
  67.          SET _NUM6=!_NUM5_%%A:~-1!!_NUM6!
  68.          ) ELSE (
  69.          SET _NUM6=!_NUM5_%%A!!_NUM6!
  70.          )
  71.       SET !_RESULT!=!_CO!!_NUM6!
  72.       )
  73.    GOTO :EOF
  74.  
  75. :END

page last modified: 2024-04-16; loaded in 0.0052 seconds