39 lines
7.3 KiB
HTML
39 lines
7.3 KiB
HTML
<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>CLHS: Section 22.3.3.1</TITLE>
|
|
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
|
|
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
|
|
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
|
|
<LINK REL=TOP HREF="../Front/index.htm">
|
|
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
|
|
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
|
|
<LINK REL=PREV HREF="22_cc.htm">
|
|
<LINK REL=UP HREF="22_cc.htm">
|
|
<LINK REL=NEXT HREF="22_ccb.htm">
|
|
</HEAD>
|
|
<BODY>
|
|
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="22_cc.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="22_cc.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="22_ccb.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<H2>
|
|
22.3.3.1 Tilde F: Fixed-Format Floating-Point</H2> <P>
|
|
The next <I>arg</I> is printed as a <A REL=DEFINITION HREF="26_glo_f.htm#float"><I>float</I></A>. <P>
|
|
The full form is <TT>~</TT><I>w</I><TT>,</TT><I>d</I><TT>,</TT><I>k</I><TT>,</TT><I>overflowchar</I><TT>,</TT><I>padchar</I><TT>F</TT>. The parameter <I>w</I> is the width of the field to be printed; <I>d</I> is the number of digits to print after the decimal point; <I>k</I> is a scale factor that defaults to zero. <P>
|
|
Exactly <I>w</I> characters will be output. First, leading copies of the character <I>padchar</I> (which defaults to a space) are printed, if necessary, to pad the field on the left. If the <I>arg</I> is negative, then a minus sign is printed; if the <I>arg</I> is not negative, then a plus sign is printed if and only if the <TT>@</TT> modifier was supplied. Then a sequence of digits, containing a single embedded decimal point, is printed; this represents the magnitude of the value of <I>arg</I> times 10^<I>k</I>, rounded to <I>d</I> fractional digits. When rounding up and rounding down would produce printed values equidistant from the scaled value of <I>arg</I>, then the implementation is free to use either one. For example, printing the argument <TT>6.375</TT> using the format <TT>~4,2F</TT> may correctly produce either <TT>6.37</TT> or <TT>6.38</TT>. Leading zeros are not permitted, except that a single zero digit is output before the decimal point if the printed value is less than one, and this single zero digit is not output at all if <I>w</I>=<I>d</I>+1. <P>
|
|
If it is impossible to print the value in the required format in a field of width <I>w</I>, then one of two actions is taken. If the parameter <I>overflowchar</I> is supplied, then <I>w</I> copies of that parameter are printed instead of the scaled value of <I>arg</I>. If the <I>overflowchar</I> parameter is omitted, then the scaled value is printed using more than <I>w</I> characters, as many more as may be needed. <P>
|
|
If the <I>w</I> parameter is omitted, then the field is of variable width. In effect, a value is chosen for <I>w</I> in such a way that no leading pad characters need to be printed and exactly <I>d</I> characters will follow the decimal point. For example, the directive <TT>~,2F</TT> will print exactly two digits after the decimal point and as many as necessary before the decimal point. <P>
|
|
If the parameter <I>d</I> is omitted, then there is no constraint on the number of digits to appear after the decimal point. A value is chosen for <I>d</I> in such a way that as many digits as possible may be printed subject to the width constraint imposed by the parameter <I>w</I> and the constraint that no trailing zero digits may appear in the fraction, except that if the fraction to be printed is zero, then a single zero digit should appear after the decimal point if permitted by the width constraint. <P>
|
|
If both <I>w</I> and <I>d</I> are omitted, then the effect is to print the value using ordinary free-format output; <A REL=DEFINITION HREF="f_wr_pr.htm#prin1"><B>prin1</B></A> uses this format for any number whose magnitude is either zero or between 10^-3 (inclusive) and 10^7 (exclusive). <P>
|
|
If <I>w</I> is omitted, then if the magnitude of <I>arg</I> is so large (or, if <I>d</I> is also omitted, so small) that more than 100 digits would have to be printed, then an implementation is free, at its discretion, to print the number using exponential notation instead, as if by the directive <TT>~E</TT> (with all parameters to <TT>~E</TT> defaulted, not taking their values from the <TT>~F</TT> directive). <P>
|
|
If <I>arg</I> is a <A REL=DEFINITION HREF="26_glo_r.htm#rational"><I>rational</I></A> number, then it is coerced to be a <A REL=DEFINITION HREF="26_glo_s.htm#single_float"><I>single float</I></A> and then printed. Alternatively, an implementation is permitted to process a <A REL=DEFINITION HREF="26_glo_r.htm#rational"><I>rational</I></A> number by any other method that has essentially the same behavior but avoids loss of precision or overflow because of the coercion. If <I>w</I> and <I>d</I> are not supplied and the number has no exact decimal representation, for example <TT>1/3</TT>, some precision cutoff must be chosen by the implementation since only a finite number of digits may be printed. <P>
|
|
If <I>arg</I> is a <A REL=DEFINITION HREF="26_glo_c.htm#complex"><I>complex</I></A> number or some non-numeric <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A>, then it is printed using the format directive <TT>~</TT><I>w</I><TT>D</TT>, thereby printing it in decimal radix and a minimum field width of <I>w</I>. <P>
|
|
<TT>~F</TT> binds <A REL=DEFINITION HREF="v_pr_esc.htm#STprint-escapeST"><B>*print-escape*</B></A> to <A REL=DEFINITION HREF="26_glo_f.htm#false"><I>false</I></A> and <A REL=DEFINITION HREF="v_pr_rda.htm#STprint-readablyST"><B>*print-readably*</B></A> to <A REL=DEFINITION HREF="26_glo_f.htm#false"><I>false</I></A>. <P>
|
|
<P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issues</A>, <I>not part of the specification</I>, apply to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss271.htm">PRINC-READABLY:X3J13-DEC-91</A><LI> <A REL=CHILD HREF="../Issues/iss169.htm">FORMAT-PRETTY-PRINT:YES</A><P></UL><HR>
|
|
|
|
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
|
|
|
|
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
|
|
</BODY>
|
|
</HTML>
|