% Copyright Massachusetts Institute of Technology 1980, 1989

f_form = proc (x: real, i, f: int) returns (string)
			signals (illegal_field_width, insufficient_field_width)
	m1 = -1
	if i < 0  cor  f < 0  cor  (i = 0  cand  f = 0)
	   then signal illegal_field_width end
	minus: bool, digits: _bytevec, expon: int := _unparse_real(x)
	ndigs: int := 0
	n: int
	if x ~= 0.0
	   then n, ndigs := _round_real(digits, expon + f)
		expon := expon + n
		if expon > i
		   then signal insufficient_field_width end
	   end
	n := f + 1
	if i > 0
	   then if expon > 0
		   then n := n + expon
			if i > expon
			   then i := expon end
		   else n := n + 1
			if i > 1
			   then i := 1 end
		   end
	   end
	if minus
	   then n := n + 1 end
	res: _bytevec := _bytevec$create(n)
	n := 1
	if minus
	   then res[1] := '-'
		n := 2
	   end
	j: int := 1
	while true do
		if i = 0
		   then res[n] := '.'
			n := n + 1
			if f = 0
			   then break end
		   end
		c: char := '0'
		if expon >= i  cand  j <= ndigs
		   then c := digits[j]
			j := j + 1
		   end
		res[n] := c
		n := n + 1
		i := i - 1
		if i >= 0
		   then continue end
		f := f - 1
		if f <= 0
		   then break end
		end
	return(_cvt[_bytevec, string](res))
	end f_form
