Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    r4e84ef7 r200fcb3  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sun Apr 14 11:02:34 2019
    14 %% Update Count     : 3443
     13%% Last Modified On : Tue Dec 11 23:19:26 2018
     14%% Update Count     : 3400
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    508508
    509509As for \Index{division}, there are exponentiation operators for integral and floating types, including the builtin \Index{complex} types.
    510 Integral 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).
    511 Overflow from large exponents or negative exponents return zero.
    512 Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the exponent cannot be negative.
    513 \begin{cfa}
    514 sout | 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);
    516 1 1 256 -64 125 ®0® 3273344365508751233 ®0® ®0® -0.015625 18.3791736799526 0.264715-1.1922i
    517 \end{cfa}
    518 Note, ©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.
     510Unsigned 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).
     511Signed 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$.
     512Hence, 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.
     513Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the base cannot be negative.
     514\begin{cfa}
     515sout | 2 ®\® 8u | 4 ®\® 3u | -4 ®\® 3u | 4 ®\® -3 | -4 ®\® -3 | 4.0 ®\® 2.1 | (1.0f+2.0fi) ®\® (3.0f+2.0fi);
     516256 64 -64 0.015625 -0.015625 18.3791736799526 0.264715-1.1922i
     517\end{cfa}
    519518Parenthesis are necessary for complex constants or the expression is parsed as ©1.0f+®(®2.0fi \ 3.0f®)®+2.0fi©.
    520 The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation version is available.
    521 \begin{cfa}
    522 forall( otype OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } )
    523 OT ?®\®?( OT ep, unsigned int y );
    524 forall( otype OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } )
    525 OT ?®\®?( OT ep, unsigned long int y );
    526 \end{cfa}
    527 The user type ©T© must define multiplication, one, ©1©, and, ©*©.
     519The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation versions are available.
     520For returning an integral value, the user type ©T© must define multiplication, ©*©, and one, ©1©;
     521for returning a floating value, an additional divide of type ©T© into a ©double© returning a ©double© (©double ?/?( double, T )©) is necessary for negative exponents.
    528522
    529523
     
    555549\subsection{Loop Control}
    556550
    557 The ©for©/©while©/©do-while© loop-control allows empty or simplified ranges (see Figure~\ref{f:LoopControlExamples}).
    558 \begin{itemize}
    559 \item
     551The ©for©/©while©/©do-while© loop-control allows empty or simplified ranges.
    560552An empty conditional implies ©1©.
    561 \item
    562 The up-to range ©~©\index{~@©~©} means exclusive range [M,N).
    563 \item
    564 The up-to range ©~=©\index{~=@©~=©} means inclusive range [M,N].
    565 \item
    566 The down-to range ©-~©\index{-~@©-~©} means exclusive range [N,M).
    567 \item
    568 The down-to range ©-~=©\index{-~=@©-~=©} means inclusive range [N,M].
    569 \item
    570 ©@© means put nothing in this field.
    571 \item
     553The up-to range ©~©\index{~@©~©} means exclusive range [M,N);
     554the up-to range ©~=©\index{~=@©~=©} means inclusive range [M,N].
     555The down-to range ©-~©\index{-~@©-~©} means exclusive range [N,M);
     556the down-to range ©-~=©\index{-~=@©-~=©} means inclusive range [N,M].
    572557©0© is the implicit start value;
    573 \item
    574558©1© is the implicit increment value.
    575 \item
    576559The up-to range uses ©+=© for increment;
    577 \item
    578 The down-to range uses ©-=© for decrement.
    579 \item
     560the down-to range uses ©-=© for decrement.
    580561The 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}
    584562\begin{cquote}
    585 \begin{tabular}{@{}l|l@{}}
    586 \multicolumn{1}{c|}{loop control} & \multicolumn{1}{c}{output} \\
     563\begin{tabular}{@{}ll|l@{}}
     564\multicolumn{2}{c|}{loop control} & \multicolumn{1}{c}{output} \\
    587565\hline
    588566\begin{cfa}
    589 sout | nlOff;
    590 while ®()® { sout | "empty"; break; } sout | nl;
    591 do { sout | "empty"; break; } while ®()®; sout | nl;
    592 for ®()® { sout | "empty"; break; } sout | nl;
    593 for ( ®0® ) { sout | "A"; } sout | "zero" | nl;
    594 for ( ®1® ) { sout | "A"; } sout | nl;
    595 for ( ®10® ) { sout | "A"; } sout | nl;
    596 for ( ®1 ~= 10 ~ 2® ) { sout | "B"; } sout | nl;
    597 for ( ®10 -~= 1 ~ 2® ) { sout | "C"; } sout | nl;
    598 for ( ®0.5 ~ 5.5® ) { sout | "D"; } sout | nl;
    599 for ( ®5.5 -~ 0.5® ) { sout | "E"; } sout | nl;
    600 for ( ®i; 10® ) { sout | i; } sout | nl;
    601 for ( ®i; 1 ~= 10 ~ 2® ) { sout | i; } sout | nl;
    602 for ( ®i; 10 -~= 1 ~ 2® ) { sout | i; } sout | nl;
    603 for ( ®i; 0.5 ~ 5.5® ) { sout | i; } sout | nl;
    604 for ( ®i; 5.5 -~ 0.5® ) { sout | i; } sout | nl;
    605 for ( ®ui; 2u ~= 10u ~ 2u® ) { sout | ui; } sout | nl;
    606 for ( ®ui; 10u -~= 2u ~ 2u® ) { sout | ui; } sout | nl;
     567while ®()® { sout | "empty"; break; }
     568do { sout | "empty"; break; } while ®()®;
     569for ®()® { sout | "empty"; break; }
     570for ( ®0® ) { sout | "A"; }
     571for ( ®1® ) { sout | "A"; }
     572for ( ®10® ) { sout | "A"; }
     573for ( ®1 ~= 10 ~ 2® ) { sout | "B"; }
     574for ( ®10 -~= 1 ~ 2® ) { sout | "C"; }
     575for ( ®0.5 ~ 5.5® ) { sout | "D"; }
     576for ( ®5.5 -~ 0.5® ) { sout | "E"; }
     577for ( ®i; 10® ) { sout | i; }
     578for ( ®i; 1 ~= 10 ~ 2® ) { sout | i; }
     579for ( ®i; 10 -~= 1 ~ 2® ) { sout | i; }
     580for ( ®i; 0.5 ~ 5.5® ) { sout | i; }
     581for ( ®i; 5.5 -~ 0.5® ) { sout | i; }
     582for ( ®ui; 2u ~= 10u ~ 2u® ) { sout | ui; }
     583for ( ®ui; 10u -~= 2u ~ 2u® ) { sout | ui; }
    607584enum { N = 10 };
    608 for ( ®N® ) { sout | "N"; } sout | nl;
    609 for ( ®i; N® ) { sout | i; } sout | nl;
    610 for ( ®i; N -~ 0® ) { sout | i; } sout | nl;
     585for ( ®N® ) { sout | "N"; }
     586for ( ®i; N® ) { sout | i; }
     587for ( ®i; N -~ 0® ) { sout | i; }
    611588const int start = 3, comp = 10, inc = 2;
    612 for ( ®i; start ~ comp ~ inc + 1® ) { sout | i; } sout | nl;
    613 for ( ®i; 1 ~ @® ) { if ( i > 10 ) break;
    614         sout | i; } sout | nl;
    615 for ( ®i; 10 -~ @® ) { if ( i < 0 ) break;
    616         sout | i; } sout | nl;
    617 for ( ®i; 2 ~ @ ~ 2® ) { if ( i > 10 ) break;
    618         sout | i; } sout | nl;
    619 for ( ®i; 2.1 ~ @ ~ @® ) { if ( i > 10.5 ) break;
    620         sout | i; i += 1.7; } sout | nl;
    621 for ( ®i; 10 -~ @ ~ 2® ) { if ( i < 0 ) break;
    622         sout | i; } sout | nl;
    623 for ( ®i; 12.1 ~ @ ~ @® ) { if ( i < 2.5 ) break;
    624         sout | i; i -= 1.7; } sout | nl;
    625 for ( ®i; 5 : j; -5 ~ @® ) { sout | i | j; } sout | nl;
    626 for ( ®i; 5 : j; -5 -~ @® ) { sout | i | j; } sout | nl;
    627 for ( ®i; 5 : j; -5 ~ @ ~ 2® ) { sout | i | j; } sout | nl;
    628 for ( ®i; 5 : j; -5 -~ @ ~ 2® ) { sout | i | j; } sout | nl;
    629 for ( ®j; -5 ~ @ : i; 5® ) { sout | i | j; } sout | nl;
    630 for ( ®j; -5 -~ @ : i; 5® ) { sout | i | j; } sout | nl;
    631 for ( ®j; -5 ~ @ ~ 2 : i; 5® ) { sout | i | j; } sout | nl;
    632 for ( ®j; -5 -~ @ ~ 2 : i; 5® ) { sout | i | j; } sout | nl;
    633 for ( ®j; -5 -~ @ ~ 2 : i; 5 : k; 1.5 ~ @® ) {
    634         sout | i | j | k; } sout | nl;
    635 for ( ®j; -5 -~ @ ~ 2 : k; 1.5 ~ @ : i; 5® ) {
    636         sout | i | j | k; } sout | nl;
    637 for ( ®k; 1.5 ~ @ : j; -5 -~ @ ~ 2 : i; 5® ) {
    638         sout | i | j | k; } sout | nl;
     589for ( ®i; start ~ comp ~ inc + 1® ) { sout | i; }
    639590\end{cfa}
    640591&
    641592\begin{cfa}
    642 
     593sout | nl;
     594sout | nl;
     595sout | nl;
     596sout | "zero" | nl;
     597sout | nl;
     598sout | nl;
     599sout | nl;
     600sout | nl;
     601sout | nl;
     602sout | nl;
     603sout | nl;
     604sout | nl;
     605sout | nl;
     606sout | nl;
     607sout | nl;
     608sout | nl;
     609sout | nl | nl;
     610
     611sout | nl;
     612sout | nl;
     613sout | nl | nl;
     614
     615sout | nl;
     616\end{cfa}
     617&
     618\begin{cfa}
    643619empty
    644620empty
     
    664640
    6656413 6 9
    666 
    667 1 2 3 4 5 6 7 8 9 10
    668 
    669 10 9 8 7 6 5 4 3 2 1 0
    670 
    671 2 4 6 8 10
    672 
    673 2.1 3.8 5.5 7.2 8.9
    674 
    675 10 8 6 4 2 0
    676 
    677 12.1 10.4 8.7 7 5.3 3.6
    678 0 -5 1 -4 2 -3 3 -2 4 -1
    679 0 -5 1 -6 2 -7 3 -8 4 -9
    680 0 -5 1 -3 2 -1 3 1 4 3
    681 0 -5 1 -7 2 -9 3 -11 4 -13
    682 0 -5 1 -4 2 -3 3 -2 4 -1
    683 0 -5 1 -6 2 -7 3 -8 4 -9
    684 0 -5 1 -3 2 -1 3 1 4 3
    685 0 -5 1 -7 2 -9 3 -11 4 -13
    686 
    687 0 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
    688 
    689 0 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
    690 
    691 0 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
    692642\end{cfa}
    693643\end{tabular}
    694644\end{cquote}
    695 \caption{Loop Control Examples}
    696 \label{f:LoopControlExamples}
    697 \end{figure}
    698645
    699646
     
    13731320\end{cfa}
    13741321Essentially, the return type is wrapped around the routine name in successive layers (like an \Index{onion}).
    1375 While 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}
    1377 In 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}
     1322While attempting to make the two contexts consistent is a laudable goal, it has not worked out in practice.
    13791323
    13801324\CFA provides its own type, variable and routine declarations, using a different syntax.
Note: See TracChangeset for help on using the changeset viewer.