next up previous
Next: Implementation issues Up: Scoping affects how we Previous: Making sense of scope

Complications

In each of the two alternatives above we are assuming that floating point modes could be treated linguistically as normal variables with normal scope for that language. In reality, setting the modes is likely to be implemented via access to special status registers in a floating-point arithmetic unit, and not just changes to memory. Thus (set rounding_mode nearest) would normally not be as simple as (set x 3.0).

(We promised not to get involved yet, but reading flags is much more complicated, and writing them is not usually possible.)

Other designs are possible and may be more explicit in showing how these modes are distinct from the variables. One can have dynamically scoped (save/ set/ restore global flags) regardless of how normal variables are treated in a language.

This leads to

ALTERNATIVE 3

Possibly special syntax

(define (f x rm)  (with_rounding_mode rm  (g x) ...))
or via compiler directive (not easy to show in Scheme, here's pseudo-Fortran)

	subroutine f(x)
C	compiler directive affecting the compilation. Until 
C	otherwise instructed (like PRAGMA)
%	rounding_mode = To_ZERO
	y=a+b
	call g(x) 
C	 rounding mode is unaffected in g, if g compiled separately
        ...
.............



Richard J. Fateman
Wed Aug 12 22:53:48 PDT 1998