Here is my rendition of the resuscitation of the Div routine ....
!
! -- Div
!
! -- DIVIDE Subroutine
! -- CALL DIVIDE (numex, numex, numvar, numvar)
! -- CALL DIVIDE (dvend, dvsor, q, r) divides dvend by dvsor to give quotient q and remainder r. More
! -- specifically, q and r are solutions to dvend = dvsor*q + r, where q = INT(dvend/dvsor) and r = MOD
! -- (dvend, dvsor). For example:
! -- Statements, Built-in Functions and Subroutines 237
! -- ! DIVIDE with these arguments ! Returns
! -- CALL DIVIDE (2.5, 1.5, q, r) ! q = 1, r = 1
! -- CALL DIVIDE (1, 10, q, r) ! q = 0, r = 1
! -- CALL DIVIDE (7, 3, q, e) ! q = 2, r = 1
! -- CALL DIVIDE (-7, 3, q, r) ! q = -3, r = 2
! -- CALL DIVIDE (7, -3, q, r) ! q = -3, r = -2
! -- CALL DIVIDE (-7, -3, q, r) ! q = 2, r = -1
! -- Exceptions: 1002 Overflow; 3001 Division by zero.
!
! -- Div as routine
!
! -- LET max_num = MAXNUM
! -- PRINT
! -- PRINT "MAXNUM, -1 * MAXUM):"; INT( max_num); INT( -1 * max_num)
! -- PRINT
! -- GET KEY zzz
!
! Copyright notice
!
PRINT
PRINT TAB( 5);
PRINT "TrueBASIC source code resuscitation of the Div routine for translation to Ada95"
PRINT
PRINT TAB( 5); "© Copyright 2024 by Colin James III All rights reserved."
PRINT
PRINT
DO
READ IF MISSING THEN EXIT DO: dividend, divisor
LET quotient = 0
LET remainder = 0
CALL Div( dividend, divisor, quotient, remainder)
PRINT "dividend, divisor, quotient, remainder ";
PRINT dividend, divisor, quotient, remainder
LOOP
PRINT
PRINT "Routine tested correctly on "; Date$; "."
PRINT
PRINT "Press any keys to end: ";
GET KEY zzz
PRINT
!
! Test data
!
DATA 2.5, 1.5 ! q, r = 1, 1
DATA 1, 10 ! q, r = 0, 1
DATA 7, 3 ! q, r = 2, 1
DATA -7, 3 ! q, r = -3, 2
DATA 7, -3 ! q, r = -3, -2
DATA -7, -3 ! q, r = 2, -1
DATA 1, 0 ! 3001 Division by zero
SUB DIV( dividend, divisor, quotient, remainder)
WHEN EXCEPTION IN
LET quotient = INT( dividend / divisor)
LET remainder = MOD( dividend, divisor)
USE
IF divisor = 0 THEN
PRINT
PRINT "Exception raised below."
PRINT
PRINT "3001 Division by zero"
ELSE
!
! The only other possible exception is an integer number greater than MAXNUM.
!
PRINT
PRINT "Exception raised below."
PRINT
PRINT "1002 Overflow"
END IF
END WHEN
END SUB ! DIV( dividend, divisor, quotient, remainder)
END ! Div as routine