1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Body/22_ccb.htm
2024-04-01 10:24:07 +02:00

40 lines
8.8 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.2</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_cca.htm">
<LINK REL=UP HREF="22_cc.htm">
<LINK REL=NEXT HREF="22_ccc.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_cca.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_ccc.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>
22.3.3.2 Tilde E: Exponential 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> in exponential notation. <P>
The full form is <TT>~</TT><I>w</I><TT>,</TT><I>d</I><TT>,</TT><I>e</I><TT>,</TT><I>k</I><TT>,</TT><I>overflowchar</I><TT>,</TT><I>padchar</I><TT>,</TT><I>exponentchar</I><TT>E</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>e</I> is the number of digits to use when printing the exponent; <I>k</I> is a scale factor that defaults to one (not 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. The form of this sequence of digits depends on the scale factor <I>k</I>. If <I>k</I> is zero, then <I>d</I> digits are printed after the decimal point, and a single zero digit appears before the decimal point if the total field width will permit it. If <I>k</I> is positive, then it must be strictly less than <I>d</I>+2; <I>k</I> significant digits are printed before the decimal point, and <I>d</I>-<I>k</I>+1 digits are printed after the decimal point. If <I>k</I> is negative, then it must be strictly greater than -<I>d</I>; a single zero digit appears before the decimal point if the total field width will permit it, and after the decimal point are printed first -<I>k</I> zeros and then <I>d</I>+<I>k</I> significant digits. The printed fraction must be properly rounded. 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>637.5</TT> using the format <TT>~8,2E</TT> may correctly produce either <TT>6.37E+2</TT> or <TT>6.38E+2</TT>. <P>
Following the digit sequence, the exponent is printed. First the character parameter <I>exponentchar</I> is printed; if this parameter is omitted, then the <A REL=DEFINITION HREF="26_glo_e.htm#exponent_marker"><I>exponent marker</I></A> that <A REL=DEFINITION HREF="f_wr_pr.htm#prin1"><B>prin1</B></A> would use is printed, as determined from the type of the <A REL=DEFINITION HREF="26_glo_f.htm#float"><I>float</I></A> and the current value of <A REL=DEFINITION HREF="v_rd_def.htm#STread-default-float-formatST"><B>*read-default-float-format*</B></A>. Next, either a plus sign or a minus sign is printed, followed by <I>e</I> digits representing the power of ten by which the printed fraction must be multiplied to properly represent the rounded value of <I>arg</I>. <P>
If it is impossible to print the value in the required format in a field of width <I>w</I>, possibly because <I>k</I> is too large or too small or because the exponent cannot be printed in <I>e</I> character positions, 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; if the problem is that <I>d</I> is too small for the supplied <I>k</I> or that <I>e</I> is too small, then a larger value is used for <I>d</I> or <I>e</I> 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. <P>
If the parameter <I>d</I> is omitted, then there is no constraint on the number of digits to appear. 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>, the constraint of the scale factor <I>k</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. <P>
If the parameter <I>e</I> is omitted, then the exponent is printed using the smallest number of digits necessary to represent its value. <P>
If all of <I>w</I>, <I>d</I>, and <I>e</I> are omitted, then the effect is to print the value using ordinary free-format exponential-notation output; <A REL=DEFINITION HREF="f_wr_pr.htm#prin1"><B>prin1</B></A> uses a similar format for any non-zero number whose magnitude is less than 10^-3 or greater than or equal to 10^7. The only difference is that the <TT>~E</TT> directive always prints a plus or minus sign in front of the exponent, while <A REL=DEFINITION HREF="f_wr_pr.htm#prin1"><B>prin1</B></A> omits the plus sign if the exponent is non-negative. <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 unsupplied 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>~E</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><LI> <A REL=CHILD HREF="../Issues/iss167.htm">FORMAT-E-EXPONENT-SIGN:FORCE-SIGN</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>