From fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Jul 2015 20:46:52 -0400 Subject: Initial commit --- sys/fmtio/pargx.x | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 sys/fmtio/pargx.x (limited to 'sys/fmtio/pargx.x') diff --git a/sys/fmtio/pargx.x b/sys/fmtio/pargx.x new file mode 100644 index 00000000..d399da29 --- /dev/null +++ b/sys/fmtio/pargx.x @@ -0,0 +1,57 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include +include +include + +# PARGX -- Pass a numeric argument of type complex to printf. Get the format +# spec and format the number on the output file. Try to provide reasonable +# automatic type conversions. Avoid any type coercion of indefinites. + +procedure pargx (xval) + +complex xval # complex value to be encoded +double value +int n, xtoc() +include "fmt.com" + +begin + call fmt_read() # read format + + if (format_char == FMT_COMPLEX || format_char == USE_DEFAULT) { + if (width == USE_DEFAULT) # print as (r,r) + width = SZ_OBUF + + if (decpl == USE_DEFAULT || decpl == 0) + decpl = NDIGITS_RP + else + decpl = abs (decpl) + + # Encode number in the available field width, decreasing the + # precision until the number fits. + + repeat { + n = xtoc (xval, obuf, SZ_OBUF, decpl, FMT_EXPON, SZ_OBUF) + decpl = decpl - 1 + } until (n <= width || decpl <= 0) + + # Move the string in OBUF to the output file, left or right + # justifying as specified. Advance to the next format spec + # (or finish up). + + if (width == SZ_OBUF) # free format? + width = 0 + call fmtstr (fd, obuf, col, fill_char, left_justify, SZ_OBUF, width) + call fpradv () + + } else { + # Print real part of complex number in some format other than + # complex. + + value = real (xval) + if (IS_INDEFR (real(xval))) + value = INDEFD + + call pargg (value, TY_REAL) + } +end -- cgit