Implement 'div0', 'mod0', and 'div0-and-mod0' in Scheme

Issue #63 new
Katie Burke created an issue

These procedures are similar to div, mod, and div-and-mod, but constrain the "mod" value differently, which also affects the "div" value. The value nd of (div0 x1 x2) is an integer, and the value xm of (mod0 x1 x2) is a real number such that x1 = nd · x2 + xm and -|x2/2| ≤ xm < |x2/2|. In situations where the implementation cannot represent the mathematical results prescribed by these equations as a number object, div0 and mod0 return an unspecified number or raise an exception with condition type &implementation-restriction. ( http://www.scheme.com/tspl4/objects.html#./objects:s100 )

This example should return 6.

(div0 17 3)

Traceback (most recent call last):
File "stdin", line 1, col 2
RunTimeError: unbound variable 'div0'

This example should return -1.

(mod0 17 3)

Traceback (most recent call last):
File "stdin", line 1, col 2
RunTimeError: unbound variable 'mod0'

This example should return 6.0 -0.5

(div0-and-mod0 17.5 3)

Traceback (most recent call last):
File "stdin", line 1, col 2
RunTimeError: unbound variable 'div0-and-mod0'

Comments (0)

  1. Log in to comment