Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    r200fcb3 r4e84ef7  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Tue Dec 11 23:19:26 2018
    14 %% Update Count     : 3400
     13%% Last Modified On : Sun Apr 14 11:02:34 2019
     14%% Update Count     : 3443
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    508508
    509509As for \Index{division}, there are exponentiation operators for integral and floating types, including the builtin \Index{complex} types.
    510 Unsigned integral exponentiation\index{exponentiation!unsigned integral} is performed with repeated multiplication\footnote{The multiplication computation is $O(\log y)$.} (or shifting if the base is 2).
    511 Signed integral exponentiation\index{exponentiation!signed integral} is performed with repeated multiplication (or shifting if the base is 2), but yields a floating result because $x^{-y}=1/x^y$.
    512 Hence, it is important to designate exponent integral-constants as unsigned or signed: ©3 \ 3u© return an integral result, while ©3 \ 3© returns a floating result.
    513 Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the base cannot be negative.
    514 \begin{cfa}
    515 sout | 2 ®\® 8u | 4 ®\® 3u | -4 ®\® 3u | 4 ®\® -3 | -4 ®\® -3 | 4.0 ®\® 2.1 | (1.0f+2.0fi) ®\® (3.0f+2.0fi);
    516 256 64 -64 0.015625 -0.015625 18.3791736799526 0.264715-1.1922i
    517 \end{cfa}
     510Integral exponentiation\index{exponentiation!unsigned integral} is performed with repeated multiplication\footnote{The multiplication computation is $O(\log y)$.} (or shifting if the exponent is 2).
     511Overflow from large exponents or negative exponents return zero.
     512Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the exponent cannot be negative.
     513\begin{cfa}
     514sout | 1 ®\® 0 | 1 ®\® 1 | 2 ®\® 8 | -4 ®\® 3 | 5 ®\® 3 | 5 ®\® 32 | 5L ®\® 32 | 5L ®\® 64 | -4 ®\® -3 | -4.0 ®\® -3 | 4.0 ®\® 2.1
     515           | (1.0f+2.0fi) ®\® (3.0f+2.0fi);
     5161 1 256 -64 125 ®0® 3273344365508751233 ®0® ®0® -0.015625 18.3791736799526 0.264715-1.1922i
     517\end{cfa}
     518Note, ©5 ®\® 32© and ©5L ®\® 64© overflow, and ©-4 ®\® -3© is a fraction but stored in an integer so all three computations generate an integral zero.
    518519Parenthesis are necessary for complex constants or the expression is parsed as ©1.0f+®(®2.0fi \ 3.0f®)®+2.0fi©.
    519 The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation versions are available.
    520 For returning an integral value, the user type ©T© must define multiplication, ©*©, and one, ©1©;
    521 for returning a floating value, an additional divide of type ©T© into a ©double© returning a ©double© (©double ?/?( double, T )©) is necessary for negative exponents.
     520The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation version is available.
     521\begin{cfa}
     522forall( otype OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } )
     523OT ?®\®?( OT ep, unsigned int y );
     524forall( otype OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } )
     525OT ?®\®?( OT ep, unsigned long int y );
     526\end{cfa}
     527The user type ©T© must define multiplication, one, ©1©, and, ©*©.
    522528
    523529
     
    549555\subsection{Loop Control}
    550556
    551 The ©for©/©while©/©do-while© loop-control allows empty or simplified ranges.
     557The ©for©/©while©/©do-while© loop-control allows empty or simplified ranges (see Figure~\ref{f:LoopControlExamples}).
     558\begin{itemize}
     559\item
    552560An empty conditional implies ©1©.
    553 The up-to range ©~©\index{~@©~©} means exclusive range [M,N);
    554 the up-to range ©~=©\index{~=@©~=©} means inclusive range [M,N].
    555 The down-to range ©-~©\index{-~@©-~©} means exclusive range [N,M);
    556 the down-to range ©-~=©\index{-~=@©-~=©} means inclusive range [N,M].
     561\item
     562The up-to range ©~©\index{~@©~©} means exclusive range [M,N).
     563\item
     564The up-to range ©~=©\index{~=@©~=©} means inclusive range [M,N].
     565\item
     566The down-to range ©-~©\index{-~@©-~©} means exclusive range [N,M).
     567\item
     568The down-to range ©-~=©\index{-~=@©-~=©} means inclusive range [N,M].
     569\item
     570©@© means put nothing in this field.
     571\item
    557572©0© is the implicit start value;
     573\item
    558574©1© is the implicit increment value.
     575\item
    559576The up-to range uses ©+=© for increment;
    560 the down-to range uses ©-=© for decrement.
     577\item
     578The down-to range uses ©-=© for decrement.
     579\item
    561580The loop index is polymorphic in the type of the start value or comparison value when start is implicitly ©0©.
     581\end{itemize}
     582
     583\begin{figure}
    562584\begin{cquote}
    563 \begin{tabular}{@{}ll|l@{}}
    564 \multicolumn{2}{c|}{loop control} & \multicolumn{1}{c}{output} \\
     585\begin{tabular}{@{}l|l@{}}
     586\multicolumn{1}{c|}{loop control} & \multicolumn{1}{c}{output} \\
    565587\hline
    566588\begin{cfa}
    567 while ®()® { sout | "empty"; break; }
    568 do { sout | "empty"; break; } while ®()®;
    569 for ®()® { sout | "empty"; break; }
    570 for ( ®0® ) { sout | "A"; }
    571 for ( ®1® ) { sout | "A"; }
    572 for ( ®10® ) { sout | "A"; }
    573 for ( ®1 ~= 10 ~ 2® ) { sout | "B"; }
    574 for ( ®10 -~= 1 ~ 2® ) { sout | "C"; }
    575 for ( ®0.5 ~ 5.5® ) { sout | "D"; }
    576 for ( ®5.5 -~ 0.5® ) { sout | "E"; }
    577 for ( ®i; 10® ) { sout | i; }
    578 for ( ®i; 1 ~= 10 ~ 2® ) { sout | i; }
    579 for ( ®i; 10 -~= 1 ~ 2® ) { sout | i; }
    580 for ( ®i; 0.5 ~ 5.5® ) { sout | i; }
    581 for ( ®i; 5.5 -~ 0.5® ) { sout | i; }
    582 for ( ®ui; 2u ~= 10u ~ 2u® ) { sout | ui; }
    583 for ( ®ui; 10u -~= 2u ~ 2u® ) { sout | ui; }
     589sout | nlOff;
     590while ®()® { sout | "empty"; break; } sout | nl;
     591do { sout | "empty"; break; } while ®()®; sout | nl;
     592for ®()® { sout | "empty"; break; } sout | nl;
     593for ( ®0® ) { sout | "A"; } sout | "zero" | nl;
     594for ( ®1® ) { sout | "A"; } sout | nl;
     595for ( ®10® ) { sout | "A"; } sout | nl;
     596for ( ®1 ~= 10 ~ 2® ) { sout | "B"; } sout | nl;
     597for ( ®10 -~= 1 ~ 2® ) { sout | "C"; } sout | nl;
     598for ( ®0.5 ~ 5.5® ) { sout | "D"; } sout | nl;
     599for ( ®5.5 -~ 0.5® ) { sout | "E"; } sout | nl;
     600for ( ®i; 10® ) { sout | i; } sout | nl;
     601for ( ®i; 1 ~= 10 ~ 2® ) { sout | i; } sout | nl;
     602for ( ®i; 10 -~= 1 ~ 2® ) { sout | i; } sout | nl;
     603for ( ®i; 0.5 ~ 5.5® ) { sout | i; } sout | nl;
     604for ( ®i; 5.5 -~ 0.5® ) { sout | i; } sout | nl;
     605for ( ®ui; 2u ~= 10u ~ 2u® ) { sout | ui; } sout | nl;
     606for ( ®ui; 10u -~= 2u ~ 2u® ) { sout | ui; } sout | nl;
    584607enum { N = 10 };
    585 for ( ®N® ) { sout | "N"; }
    586 for ( ®i; N® ) { sout | i; }
    587 for ( ®i; N -~ 0® ) { sout | i; }
     608for ( ®N® ) { sout | "N"; } sout | nl;
     609for ( ®i; N® ) { sout | i; } sout | nl;
     610for ( ®i; N -~ 0® ) { sout | i; } sout | nl;
    588611const int start = 3, comp = 10, inc = 2;
    589 for ( ®i; start ~ comp ~ inc + 1® ) { sout | i; }
     612for ( ®i; start ~ comp ~ inc + 1® ) { sout | i; } sout | nl;
     613for ( ®i; 1 ~ @® ) { if ( i > 10 ) break;
     614        sout | i; } sout | nl;
     615for ( ®i; 10 -~ @® ) { if ( i < 0 ) break;
     616        sout | i; } sout | nl;
     617for ( ®i; 2 ~ @ ~ 2® ) { if ( i > 10 ) break;
     618        sout | i; } sout | nl;
     619for ( ®i; 2.1 ~ @ ~ @® ) { if ( i > 10.5 ) break;
     620        sout | i; i += 1.7; } sout | nl;
     621for ( ®i; 10 -~ @ ~ 2® ) { if ( i < 0 ) break;
     622        sout | i; } sout | nl;
     623for ( ®i; 12.1 ~ @ ~ @® ) { if ( i < 2.5 ) break;
     624        sout | i; i -= 1.7; } sout | nl;
     625for ( ®i; 5 : j; -5 ~ @® ) { sout | i | j; } sout | nl;
     626for ( ®i; 5 : j; -5 -~ @® ) { sout | i | j; } sout | nl;
     627for ( ®i; 5 : j; -5 ~ @ ~ 2® ) { sout | i | j; } sout | nl;
     628for ( ®i; 5 : j; -5 -~ @ ~ 2® ) { sout | i | j; } sout | nl;
     629for ( ®j; -5 ~ @ : i; 5® ) { sout | i | j; } sout | nl;
     630for ( ®j; -5 -~ @ : i; 5® ) { sout | i | j; } sout | nl;
     631for ( ®j; -5 ~ @ ~ 2 : i; 5® ) { sout | i | j; } sout | nl;
     632for ( ®j; -5 -~ @ ~ 2 : i; 5® ) { sout | i | j; } sout | nl;
     633for ( ®j; -5 -~ @ ~ 2 : i; 5 : k; 1.5 ~ @® ) {
     634        sout | i | j | k; } sout | nl;
     635for ( ®j; -5 -~ @ ~ 2 : k; 1.5 ~ @ : i; 5® ) {
     636        sout | i | j | k; } sout | nl;
     637for ( ®k; 1.5 ~ @ : j; -5 -~ @ ~ 2 : i; 5® ) {
     638        sout | i | j | k; } sout | nl;
    590639\end{cfa}
    591640&
    592641\begin{cfa}
    593 sout | nl;
    594 sout | nl;
    595 sout | nl;
    596 sout | "zero" | nl;
    597 sout | nl;
    598 sout | nl;
    599 sout | nl;
    600 sout | nl;
    601 sout | nl;
    602 sout | nl;
    603 sout | nl;
    604 sout | nl;
    605 sout | nl;
    606 sout | nl;
    607 sout | nl;
    608 sout | nl;
    609 sout | nl | nl;
    610 
    611 sout | nl;
    612 sout | nl;
    613 sout | nl | nl;
    614 
    615 sout | nl;
    616 \end{cfa}
    617 &
    618 \begin{cfa}
     642
    619643empty
    620644empty
     
    640664
    6416653 6 9
     666
     6671 2 3 4 5 6 7 8 9 10
     668
     66910 9 8 7 6 5 4 3 2 1 0
     670
     6712 4 6 8 10
     672
     6732.1 3.8 5.5 7.2 8.9
     674
     67510 8 6 4 2 0
     676
     67712.1 10.4 8.7 7 5.3 3.6
     6780 -5 1 -4 2 -3 3 -2 4 -1
     6790 -5 1 -6 2 -7 3 -8 4 -9
     6800 -5 1 -3 2 -1 3 1 4 3
     6810 -5 1 -7 2 -9 3 -11 4 -13
     6820 -5 1 -4 2 -3 3 -2 4 -1
     6830 -5 1 -6 2 -7 3 -8 4 -9
     6840 -5 1 -3 2 -1 3 1 4 3
     6850 -5 1 -7 2 -9 3 -11 4 -13
     686
     6870 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
     688
     6890 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
     690
     6910 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
    642692\end{cfa}
    643693\end{tabular}
    644694\end{cquote}
     695\caption{Loop Control Examples}
     696\label{f:LoopControlExamples}
     697\end{figure}
    645698
    646699
     
    13201373\end{cfa}
    13211374Essentially, the return type is wrapped around the routine name in successive layers (like an \Index{onion}).
    1322 While attempting to make the two contexts consistent is a laudable goal, it has not worked out in practice.
     1375While attempting to make the two contexts consistent is a laudable goal, it has not worked out in practice, even though Dennis Richie believed otherwise:
     1376\begin{quote}
     1377In spite of its difficulties, I believe that the C's approach to declarations remains plausible, and am comfortable with it; it is a useful unifying principle.~\cite[p.~12]{Ritchie93}
     1378\end{quote}
    13231379
    13241380\CFA provides its own type, variable and routine declarations, using a different syntax.
Note: See TracChangeset for help on using the changeset viewer.