5

I'm using Gforth, and I've looked for a standard Forth word for dividing two double integers, or at least a mixed division of a double integer by a single integer, yet supporting double integers as a result. There doesn't seem to be one. SM/REM, FM/MOD and UM/MOD have all limitations.

Did I miss anything? Why wouldn't such a word already come built-in with Forth? The operation is well-defined and no arithmetic overflows can happen. Is it necessary to program it myself?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
viuser
  • 953
  • 6
  • 19
  • 3
    Just short hint: you can use `DU/MOD` word in the well know [bigmath library](https://bitbucket.org/tgunr/usr/raw/master/share/SwiftForth/lib/options/bigmath.f) from SwitfForth. – ruvim Feb 21 '17 at 14:25

1 Answers1

1

M*/ (d n u -- result) may be the word you're looking for. From Starting Forth (the original print version):

Multiplies a 32-bit number by a 16-bit number and divides the triple-length result by a 16-bit number (d*n/u). Returns a 32-bit result. All values are signed.

So to divide a double by a single, you could subtitute n for 1. Included in DPANS94, "The optional Double-Number word set".

ruvim
  • 7,151
  • 2
  • 27
  • 36
dch
  • 213
  • 1
  • 5