How to resolve the algorithm Long multiplication step by step in the Oforth programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Long multiplication step by step in the Oforth programming language

Table of Contents

Problem Statement

Explicitly implement   long multiplication.
This is one possible approach to arbitrary-precision integer algebra.

For output, display the result of   264 * 264. Optionally, verify your result against builtin arbitrary precision support. The decimal representation of   264   is: The output of   264 * 264   is   2128,   and is:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Long multiplication step by step in the Oforth programming language

Source code in the oforth programming language

Number Class new: Natural(v)
 
Natural method: initialize  := v ;
Natural method: _v  @v ;
 
Natural classMethod: newValues super new ;
Natural classMethod: newFrom   asList self newValues ;
 
Natural method: *(n)
| v i j l x k |
   n _v ->v
   ListBuffer initValue(@v size v size + 1+, 0) ->l
 
   v size loop: i [
      i v at dup ->x 0 ifEq: [ continue ]
      0 @v size loop: j [
         i j + 1- ->k
         j @v at x * + l at(k) + 1000000000 /mod k rot l put
         ]
      k 1+ swap l put
      ]
   while(l last 0 == l size 0 <> and) [ l removeLast drop ]
   l dup freeze Natural newValues ;
 
Natural method: <<
| i |
   @v last <<
   @v size 1 - loop: i [ @v at(@v size i -) <

  

You may also check:How to resolve the algorithm Horner's rule for polynomial evaluation step by step in the Logo programming language
You may also check:How to resolve the algorithm Probabilistic choice step by step in the ReScript programming language
You may also check:How to resolve the algorithm Bitmap/Read a PPM file step by step in the Tcl programming language
You may also check:How to resolve the algorithm Read a file character by character/UTF8 step by step in the Tcl programming language
You may also check:How to resolve the algorithm Variadic function step by step in the Modula-3 programming language