Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dividing two double integers in Forth

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?

like image 925
viuser Avatar asked Nov 09 '22 01:11

viuser


1 Answers

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".

like image 70
dch Avatar answered Dec 31 '22 00:12

dch