Changeset fe97a7d8


Ignore:
Timestamp:
Jul 22, 2017, 11:05:35 AM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
637ff81, 72457b6
Parents:
6b0b624
git-author:
Peter A. Buhr <pabuhr@…> (07/22/17 10:59:19)
git-committer:
Peter A. Buhr <pabuhr@…> (07/22/17 11:05:35)
Message:

updates to exponential operator

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    r6b0b624 rfe97a7d8  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Mon Jul 17 13:06:40 2017
    14 %% Update Count     : 2825
     13%% Last Modified On : Sat Jul 22 11:01:19 2017
     14%% Update Count     : 2878
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    251251The first \CFA implementation of these extensions was by Esteves~\cite{Esteves04}.
    252252
    253 The signature feature of \CFA is \Index{overload}able \Index{parametric-polymorphic} functions~\cite{forceone:impl,Cormack90,Duggan96} with functions generalized using a ©forall© clause (giving the language its name):
     253The signature feature of \CFA is \emph{\Index{overload}able} \Index{parametric-polymorphic} functions~\cite{forceone:impl,Cormack90,Duggan96} with functions generalized using a ©forall© clause (giving the language its name):
    254254\begin{lstlisting}
    255255®forall( otype T )® T identity( T val ) { return val; }
     
    257257\end{lstlisting}
    258258% extending the C type system with parametric polymorphism and overloading, as opposed to the \Index*[C++]{\CC{}} approach of object-oriented extensions.
    259 \CFA{}\hspace{1pt}'s polymorphism was originally formalized by Ditchfiled~\cite{Ditchfield92}, and first implemented by Bilson~\cite{Bilson03}.
     259\CFA{}\hspace{1pt}'s polymorphism was originally formalized by Ditchfield~\cite{Ditchfield92}, and first implemented by Bilson~\cite{Bilson03}.
    260260However, at that time, there was little interesting in extending C, so work did not continue.
    261261As the saying goes, ``\Index*{What goes around, comes around.}'', and there is now renewed interest in the C programming language because of legacy code-bases, so the \CFA project has been restarted.
     
    270270Language developers often state that adequate \Index{library support} takes more work than designing and implementing the language itself.
    271271Fortunately, \CFA, like \Index*[C++]{\CC{}}, starts with immediate access to all exiting C libraries, and in many cases, can easily wrap library routines with simpler and safer interfaces, at very low cost.
    272 Hence, \CFA begins by leveraging the large repository of C libraries at little cost.
     272Hence, \CFA begins by leveraging the large repository of C libraries, and than allows programmers to incrementally augment their C programs with modern \Index{backward-compatible} features.
    273273
    274274\begin{comment}
     
    318318\begin{cfa}
    319319char abs( char );
    320 ®extern "C" {®
    321 int abs( int );                                                 §\C{// use default C routine for int}§
    322 ®}® // extern "C"
     320®extern "C" {® int abs( int ); ®}®              §\C{// use default C routine for int}§
    323321long int abs( long int );
    324322long long int abs( long long int );
     
    335333Hence, there is the same need as in \CC, to know if a name is a C or \CFA name, so it can be correctly formed.
    336334There is no way around this problem, other than C's approach of creating unique names for each pairing of operation and type.
     335
    337336This example strongly illustrates a core idea in \CFA: \emph{the \Index{power of a name}}.
    338337The name ``©abs©'' evokes the notion of absolute value, and many mathematical types provide the notion of absolute value.
     
    343342\section[Compiling a CFA Program]{Compiling a \CFA Program}
    344343
    345 The command ©cfa© is used to compile \CFA program(s), and is based on the GNU \Indexc{gcc} command, \eg:
     344The command ©cfa© is used to compile a \CFA program and is based on the \Index{GNU} \Indexc{gcc} command, \eg:
    346345\begin{cfa}
    347346cfa§\indexc{cfa}\index{compilation!cfa@©cfa©}§ [ gcc-options ] C/§\CFA{}§-files [ assembler/loader-files ]
     
    361360\Indexc{-CFA}\index{compilation option!-CFA@©-CFA©}
    362361Only the C preprocessor and the \CFA translator steps are performed and the transformed program is written to standard output, which makes it possible to examine the code generated by the \CFA translator.
    363 The generated code started with the standard \CFA prelude.
     362The generated code starts with the standard \CFA \Index{prelude}.
    364363
    365364\item
     
    373372\Indexc{-nodebug}\index{compilation option!-nodebug@©-nodebug©}
    374373The program is linked with the non-debugging version of the runtime system, so the execution of the program is faster.
    375 \Emph{However, no runtime checks or ©assert©s are performed so errors usually result in abnormal program termination.}
     374\Emph{However, no runtime checks or ©assert©s are performed so errors usually result in abnormal program behaviour or termination.}
    376375
    377376\item
     
    393392\textbf{This option is the default.}
    394393
     394\begin{comment}
    395395\item
    396396\Indexc{-no-include-stdhdr}\index{compilation option!-no-include-stdhdr@©-no-include-stdhdr©}
    397397Do not supply ©extern "C"© wrappers for \Celeven standard include files (see~\VRef{s:StandardHeaders}).
    398398\textbf{This option is \emph{not} the default.}
     399\end{comment}
    399400\end{description}
    400401
     
    417418\item
    418419\Indexc{__CFA__}\index{preprocessor variables!__CFA__@©__CFA__©},
    419 \Indexc{__CFORALL__}\index{preprocessor variables!__CFORALL__@©__CFORALL__©} and
     420\Indexc{__CFORALL__}\index{preprocessor variables!__CFORALL__@©__CFORALL__©}, and
    420421\Indexc{__cforall}\index{preprocessor variables!__cforall@©__cforall©}
    421422are always available during preprocessing and have no value.
     
    470471\label{s:BackquoteIdentifiers}
    471472
    472 \CFA introduces in new keywords (see \VRef{s:CFAKeywords}) that can clash with existing C variable-names in legacy code.
     473\CFA introduces several new keywords (see \VRef{s:CFAKeywords}) that can clash with existing C variable-names in legacy code.
    473474Keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism:
    474475\begin{cfa}
     
    476477double ®`®forall®`® = 3.5;
    477478\end{cfa}
     479
    478480Existing C programs with keyword clashes can be converted by enclosing keyword identifiers in backquotes, and eventually the identifier name can be changed to a non-keyword name.
    479 \VRef[Figure]{f:HeaderFileInterposition} shows how clashes in C header files (see~\VRef{s:StandardHeaders}) can be handled using preprocessor \newterm{interposition}: ©#include_next© and ©-I filename©:
     481\VRef[Figure]{f:HeaderFileInterposition} shows how clashes in existing C header-files (see~\VRef{s:StandardHeaders}) can be handled using preprocessor \newterm{interposition}: ©#include_next© and ©-I filename©.
     482Several common C header-files with keyword clashes are fixed in the standard \CFA header-library, so there is a seamless programming-experience.
    480483
    481484\begin{figure}
    482485\begin{cfa}
    483 // include file uses the CFA keyword "otype".
    484 #if ! defined( otype )                  §\C{// nesting ?}§
    485 #define otype ®`®otype®`®               §\C{// make keyword an identifier}§
     486// include file uses the CFA keyword "with".
     487#if ! defined( with )                   §\C{// nesting ?}§
     488#define with ®`®with®`®                 §\C{// make keyword an identifier}§
    486489#define __CFA_BFD_H__
    487490#endif
    488491
    489 ®#include_next <bfd.h>                  §\C{// must have internal check for multiple expansion}§
     492®#include_next <bfdlink.h>              §\C{// must have internal check for multiple expansion}§
    490493®
    491 #if defined( otype ) && defined( __CFA_BFD_H__ )        §\C{// reset only if set}§
    492 #undef otype
     494#if defined( with ) && defined( __CFA_BFD_H__ ) §\C{// reset only if set}§
     495#undef with
    493496#undef __CFA_BFD_H__
    494497#endif
     
    499502
    500503
    501 \section{Exponentiation Operator}
    502 
    503 C, \CC, and Java (and many other programming languages) have no exponentiation operator\index{exponentiation!operator}\index{operator!exponentiation}, \ie $x^y$, and instead use a routine, like \Indexc{pow}, to perform the exponentiation operation.
    504 \CFA extends the basic operators with the exponentiation operator ©?\?©\index{?\\?@\lstinline$?\?$} and ©?\=?©\index{?\\=?@\lstinline$?\=?$}, as in, ©x \ y© and ©x \= y©, which means $x^y$ and $x \leftarrow x^y$.
    505 The priority of the exponentiation operator is between the cast and multiplicative operators, so that ©w * (int)x \ (int)y * z© is parenthesized as ©((w * (((int)x) \ ((int)y))) * z)©.
    506 
    507 As for \Index{division}, there are exponentiation operators for integral and floating-point types, including the builtin \Index{complex} types.
    508 Unsigned integral exponentiation\index{exponentiation!unsigned integral} is performed with repeated multiplication (or shifting if the base is 2).
    509 Signed integral exponentiation\index{exponentiation!signed integral} is performed with repeated multiplication (or shifting if the base is 2), but yields a floating-point result because $b^{-e}=1/b^e$.
    510 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-point result.
    511 Floating-point exponentiation\index{exponentiation!floating point} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the base cannot be negative.
    512 \begin{cfa}
    513 sout | 2 ®\® 8u | 4 ®\® 3u | -4 ®\® 3u | 4 ®\® -3 | -4 ®\® -3 | 4.0 ®\® 2.1 | (1.0f+2.0fi) ®\® (3.0f+2.0fi) | endl;
    514 256 64 -64 0.015625 -0.015625 18.3791736799526 0.264715-1.1922i
    515 \end{cfa}
    516 Parenthesis are necessary for the complex constants or the expresion is parsed as ©1.0f+(2.0fi \ 3.0f)+2.0fi©.
    517 The exponentiation operator is available for all the basic types, but for user-defined types, only the integral version is available, if the user type defines multiplication, ©*©, and one, ©1©.
    518 
    519 
    520504\section{\texorpdfstring{Labelled \LstKeywordStyle{continue} / \LstKeywordStyle{break}}{Labelled continue / break}}
    521505
    522506While C provides ©continue© and ©break© statements for altering control flow, both are restricted to one level of nesting for a particular control structure.
    523507Unfortunately, this restriction forces programmers to use \Indexc{goto} to achieve the equivalent control-flow for more than one level of nesting.
    524 To prevent having to switch to the ©goto©, \CFA extends the \Indexc{continue}\index{continue@\lstinline $continue$!labelled}\index{labelled!continue@©continue©} and \Indexc{break}\index{break@\lstinline $break$!labelled}\index{labelled!break@©break©} with a target label to support static multi-level exit\index{multi-level exit}\index{static multi-level exit}~\cite{Buhr85}.
     508To prevent having to switch to the ©goto©, \CFA extends the \Indexc{continue}\index{continue@\lstinline $continue$!labelled}\index{labelled!continue@©continue©} and \Indexc{break}\index{break@\lstinline $break$!labelled}\index{labelled!break@©break©} with a target label to support static multi-level exit\index{multi-level exit}\index{static multi-level exit}~\cite{Buhr85}, as in Java.
    525509For both ©continue© and ©break©, the target label must be directly associated with a ©for©, ©while© or ©do© statement;
    526510for ©break©, the target label can also be associated with a ©switch©, ©if© or compound (©{}©) statement.
    527511\VRef[Figure]{f:MultiLevelResumeTermination} shows the labelled ©continue© and ©break©, specifying which control structure is the target for exit, and the corresponding C program using only ©goto©.
    528512The innermost loop has 7 exit points, which cause resumption or termination of one or more of the 7 \Index{nested control-structure}s.
    529 Java supports both labelled ©continue© and ©break© statements.
    530513
    531514\begin{figure}
     
    540523                        ®LF:® for ( ... ) {
    541524                                ®LW:® while ( ... ) {
    542                                         ... break ®LC®; ...                     // terminate compound
    543                                         ... break ®LS®; ...                     // terminate switch
    544                                         ... break ®LIF®; ...                    // terminate if
    545                                         ... continue ®LF;® ...   // resume loop
    546                                         ... break ®LF®; ...                     // terminate loop
    547                                         ... continue ®LW®; ...   // resume loop
    548                                         ... break ®LW®; ...               // terminate loop
     525                                        ... break ®LC®; ...             // terminate compound
     526                                        ... break ®LS®; ...             // terminate switch
     527                                        ... break ®LIF®; ...    // terminate if
     528                                        ... continue ®LF;® ...  // resume loop
     529                                        ... break ®LF®; ...             // terminate loop
     530                                        ... continue ®LW®; ...  // resume loop
     531                                        ... break ®LW®; ...             // terminate loop
    549532                                } // while
    550533                        } // for
    551534                } else {
    552                         ... break ®LIF®; ...                                     // terminate if
     535                        ... break ®LIF®; ...                    // terminate if
    553536                } // if
    554537        } // switch
     
    592575                          LF: for ( ;; ) {
    593576                                  LW: while ( 1 ) {
    594                                                 break LC;                       // terminate compound
    595                                                 break LS;                       // terminate switch
    596                                                 break LIF;                      // terminate if
    597                                                 continue LF;     // resume loop
    598                                                 break LF;                       // terminate loop
    599                                                 continue LW;     // resume loop
    600                                                 break LW;                 // terminate loop
     577                                                break LC;               // terminate compound
     578                                                break LS;               // terminate switch
     579                                                break LIF;              // terminate if
     580                                                continue LF;    // resume loop
     581                                                break LF;               // terminate loop
     582                                                continue LW;    // resume loop
     583                                                break LW;               // terminate loop
    601584                                        } // while
    602585                                } // for
    603586                        } else {
    604                                 break LIF;                                      // terminate if
     587                                break LIF;                              // terminate if
    605588                        } // if
    606589                } // switch
     
    641624\item
    642625They cannot branch into a control structure.
    643 This restriction prevents missing initialization at the start of a control structure resulting in undefined behaviour.
     626This restriction prevents missing declarations and/or initializations at the start of a control structure resulting in undefined behaviour.
    644627\end{itemize}
    645628The advantage of the labelled ©continue©/©break© is allowing static multi-level exits without having to use the ©goto© statement, and tying control flow to the target control structure rather than an arbitrary point in a program.
    646 Furthermore, the location of the label at the \emph{beginning} of the target control structure informs the reader that complex control-flow is occurring in the body of the control structure.
     629Furthermore, the location of the label at the \emph{beginning} of the target control structure informs the reader (\Index{eye candy}) that complex control-flow is occurring in the body of the control structure.
    647630With ©goto©, the label is at the end of the control structure, which fails to convey this important clue early enough to the reader.
    648631Finally, using an explicit target for the transfer instead of an implicit target allows new constructs to be added or removed without affecting existing constructs.
     
    736719The problem with this usage is branching into control structures, which is known to cause both comprehension and technical difficulties.
    737720The comprehension problem occurs from the inability to determine how control reaches a particular point due to the number of branches leading to it.
    738 The technical problem results from the inability to ensure allocation and initialization of variables when blocks are not entered at the beginning.
    739 Often transferring into a block can bypass variable declaration and/or its initialization, which results in subsequent errors.
    740 There are virtually no positive arguments for this kind of control flow, and therefore, there is a strong impetus to eliminate it.
     721The technical problem results from the inability to ensure declaration and initialization of variables when blocks are not entered at the beginning.
     722There are no positive arguments for this kind of control flow, and therefore, there is a strong impetus to eliminate it.
    741723Nevertheless, C does have an idiom where this capability is used, known as ``\Index*{Duff's device}''~\cite{Duff83}:
    742724\begin{cfa}
     
    954936but it is cumbersome having to write "©this.©" many times in a member.
    955937
    956 \CFA provides a ©with© clause/statement to elided the "©this.©" by opening a scope containing field identifiers and changing the qualified fields into variables, giving an opportunity for optimizing qualified references.\footnote{
    957 The ©with© statement comes from Pascal~\cite[\S~4.F]{Pascal}.}
    958 \begin{cfa}
    959 int mem( S &this ) ®with this® {
     938\CFA provides a ©with© clause/statement (see Pascal~\cite[\S~4.F]{Pascal}) to elided the "©this.©" by opening a scope containing field identifiers, changing the qualified fields into variables and giving an opportunity for optimizing qualified references.
     939\begin{cfa}
     940int mem( S &this ) ®with this® {        // with clause
    960941        i = 1;                  ®// this.i
    961942®       j = 2;                  ®// this.j
     
    976957        struct S1 { ... } s1;
    977958        struct S2 { ... } s2;
    978         ®with s1® {
     959        ®with s1® {                     // with statement
    979960                // access fields of s1 without qualification
    980961                ®with s2® {  // nesting
     
    994975struct T { int i; int k; int m } b, c;
    995976®with a, b® {
    996         j + k;                                          §\C{// unambiguous, unique names define unique type
     977        j + k;                                          §\C{// unambiguous, unique names define unique types
    997978        i;                                                      §\C{// ambiguous, same name and type}§
    998         a.i + b.i;                                      §\C{// unambiguous, qualification defines unique type
    999         m;                                                      §\C{// ambiguous, no context to define unique type}§
    1000         m = 5.0;                                        §\C{// unambiguous, context defines unique type}§
    1001         m = 1;                                          §\C{// unambiguous, context defines unique type}§
    1002 }
    1003 ®with c® { ... }                                §\C{// ambiguous, no context}§
    1004 ®with (S)c® { ... }                             §\C{// unambiguous, cast defines unique type}§
     979        a.i + b.i;                                      §\C{// unambiguous, qualification defines unique names
     980        m;                                                      §\C{// ambiguous, same name and no context to define unique type}§
     981        m = 5.0;                                        §\C{// unambiguous, same name and context defines unique type}§
     982        m = 1;                                          §\C{// unambiguous, same name and context defines unique type}§
     983}
     984®with c® { ... }                                §\C{// ambiguous, same name and no context}§
     985®with (S)c® { ... }                             §\C{// unambiguous, same name and cast defines unique type}§
    1005986\end{cfa}
    1006987
     
    10281009}
    10291010\end{cfa}
    1030 The kind of raise and handler match: ©throw© with ©catch© and @throwResume@ with @catchResume@.
     1011The kind of raise and handler match: ©throw© with ©catch© and ©throwResume© with ©catchResume©.
    10311012Then the exception type must match along with any additonal predicate must be true.
    10321013The ©catch© and ©catchResume© handlers may appear in any oder.
    1033 However, the ©finally© clause must
     1014However, the ©finally© clause must appear at the end of the ©try© statement.
    10341015
    10351016
     
    12421223
    12431224
     1225\section{Exponentiation Operator}
     1226
     1227C, \CC, and Java (and many other programming languages) have no exponentiation operator\index{exponentiation!operator}\index{operator!exponentiation}, \ie $x^y$, and instead use a routine, like \Indexc{pow}, to perform the exponentiation operation.
     1228\CFA extends the basic operators with the exponentiation operator ©?\?©\index{?\\?@\lstinline$?\?$} and ©?\=?©\index{?\\=?@\lstinline$?\=?$}, as in, ©x \ y© and ©x \= y©, which means $x^y$ and $x \leftarrow x^y$.
     1229The priority of the exponentiation operator is between the cast and multiplicative operators, so that ©w * (int)x \ (int)y * z© is parenthesized as ©((w * (((int)x) \ ((int)y))) * z)©.
     1230
     1231As for \Index{division}, there are exponentiation operators for integral and floating-point types, including the builtin \Index{complex} types.
     1232Unsigned integral exponentiation\index{exponentiation!unsigned integral} is performed with repeated multiplication (or shifting if the base is 2).
     1233Signed integral exponentiation\index{exponentiation!signed integral} is performed with repeated multiplication (or shifting if the base is 2), but yields a floating-point result because $b^{-e}=1/b^e$.
     1234Hence, it is important to designate exponent integral-constants as unsigned or signed: ©3 \ 3u© return an integral result, while ©3 \ 3© returns a floating-point result.
     1235Floating-point exponentiation\index{exponentiation!floating point} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the base cannot be negative.
     1236\begin{cfa}
     1237sout | 2 ®\® 8u | 4 ®\® 3u | -4 ®\® 3u | 4 ®\® -3 | -4 ®\® -3 | 4.0 ®\® 2.1 | (1.0f+2.0fi) ®\® (3.0f+2.0fi) | endl;
     1238256 64 -64 0.015625 -0.015625 18.3791736799526 0.264715-1.1922i
     1239\end{cfa}
     1240Parenthesis are necessary for the complex constants or the expresion is parsed as ©1.0f+(2.0fi \ 3.0f)+2.0fi©.
     1241The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation versions are available.
     1242For returning an integral value, the user type ©T© must define multiplication, ©*©, and one, ©1©;
     1243for returning a floating-point value, an additional divide of type ©T© into a ©double© returning a ©double© (©double ?/?( double, T )©) is necessary for negative exponents.
     1244
     1245
    12441246\section{Pointer / Reference}
    12451247
     
    12501252An integer constant expression with the value 0, or such an expression cast to type ©void *©, is called a \newterm{null-pointer constant}.\footnote{
    12511253One way to conceptualize the null pointer is that no variable is placed at this address, so the null-pointer address can be used to denote an uninitialized pointer/reference object;
    1252 \ie the null pointer is guaranteed to compare unequal to a pointer to any object or routine.}
     1254\ie the null pointer is guaranteed to compare unequal to a pointer to any object or routine.
     1255In general, a value with special meaning among a set of values is called a \emph{\Index{sentinel value}}, \eg ©-1© as a return code value.}
    12531256An address is \newterm{sound}, if it points to a valid memory location in scope, \ie within the program's execution-environment and has not been freed.
    12541257Dereferencing an \newterm{unsound} address, including the null pointer, is \Index{undefined}, often resulting in a \Index{memory fault}.
     
    12851288\hline
    12861289\begin{cfa}
    1287 lda             r1,100                  // load address of x
    1288 ld               r2,(r1)                  // load value of x
    1289 lda             r3,104                  // load address of y
    1290 st               r2,(r3)                  // store x into y
     1290lda             r1,100  // load address of x
     1291ld               r2,(r1)          // load value of x
     1292lda             r3,104  // load address of y
     1293st               r2,(r3)          // store x into y
    12911294\end{cfa}
    12921295&
    12931296\begin{cfa}
    12941297
    1295 ld              r2,(100)                // load value of x
    1296 
    1297 st              r2,(104)                // store x into y
     1298ld              r2,(100)        // load value of x
     1299
     1300st              r2,(104)        // store x into y
    12981301\end{cfa}
    12991302\end{tabular}
     
    32653268\Indexc{gcc} provides ©typeof© to declare a secondary variable from a primary variable.
    32663269\CFA also relies heavily on the specification of the left-hand side of assignment for type inferencing, so in many cases it is crucial to specify the type of the left-hand side to select the correct type of the right-hand expression.
    3267 Only for overloaded routines with the same return type is variable type-inferencing possible.
     3270Only for overloaded routines \emph{with the same return type} is variable type-inferencing possible.
    32683271Finally, ©auto© presents the programming problem of tracking down a type when the type is actually needed.
    32693272For example, given
     
    54075410©try©                   \\
    54085411©ttype©                 \\
     5412©with©                  \\
    54095413©zero_t©                \\
    5410                                 \\
    54115414\end{tabular}
    54125415\end{tabular}
     
    54425445g( p1, p2 ) int p1, p2;                 §\C{// int g( int p1, int p2 );}§
    54435446\end{cfa}
    5444 \CFA supports K\&R routine definitions:
     5447\CFA continues to support K\&R routine definitions:
    54455448\begin{cfa}
    54465449f( a, b, c )                                    §\C{// default int return}§
  • src/prelude/builtins.c

    r6b0b624 rfe97a7d8  
    1010// Created On       : Fri Jul 21 16:21:03 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 17:01:54 2017
    13 // Update Count     : 11
     12// Last Modified On : Sat Jul 22 10:34:20 2017
     13// Update Count     : 13
    1414//
    1515
     
    3838static inline long double _Complex ?\?( long double _Complex x, _Complex long double y ) { return cpowl( x, y ); }
    3939
    40 static inline long int ?\?( long int pe, unsigned long y ) { // disallow negative exponent
     40static inline long int ?\?( long int ep, unsigned long int y ) { // disallow negative exponent
    4141        if ( y == 0 ) return 1;                                                         // base case
    42     if ( pe == 2 ) return pe << (y - 1);                                // special case, positive shifting only
    43     typeof( pe ) po = 1;                                                                // accumulate odd product
     42    if ( ep == 2 ) return ep << (y - 1);                                // special case, positive shifting only
     43    typeof( ep ) op = 1;                                                                // accumulate odd product
    4444    for ( ; y > 1; y >>= 1 ) {                                                  // squaring exponentiation, O(log2 y)
    45                 if ( (y & 1) == 1 ) po *= pe;                                   // odd ?
    46                 pe *= pe;
    47         } // while
    48     return pe * po;
     45                if ( (y & 1) == 1 ) op *= ep;                                   // odd ?
     46                ep *= ep;
     47        } // for
     48    return ep * op;
    4949} // ?\?
    5050
    51 // FIX ME, cannot resolve the "T po = 1".
     51// FIX ME, cannot resolve the "T op = 1".
    5252
    5353// static inline forall( otype T | { void ?{}( T * this, one_t ); T ?*?( T, T ); } )
    54 // T ?\?( T pe, unsigned long y ) {
     54// T ?\?( T ep, unsigned long int y ) {
    5555//     if ( y == 0 ) return 1;
    56 //     T po = 1;
     56//     T op = 1;
    5757//     for ( ; y > 1; y >>= 1 ) {                                                       // squaring exponentiation, O(log2 y)
    58 //              if ( (y & 1) == 1 ) po = po * pe;                               // odd ?
    59 //              pe = pe * pe;
     58//              if ( (y & 1) == 1 ) op = op * ep;                               // odd ?
     59//              ep = ep * ep;
    6060//     } // for
    61 //     return pe * po;
     61//     return ep * op;
    6262// } // ?\?
    6363
    6464// unsigned computation may be faster and larger
    65 static inline unsigned long int ?\?( unsigned long int pe, unsigned long y ) { // disallow negative exponent
     65static inline unsigned long int ?\?( unsigned long int ep, unsigned long int y ) { // disallow negative exponent
    6666        if ( y == 0 ) return 1;                                                         // base case
    67     if ( pe == 2 ) return pe << (y - 1);                                // special case, positive shifting only
    68     typeof( pe ) po = 1;                                                                // accumulate odd product
     67    if ( ep == 2 ) return ep << (y - 1);                                // special case, positive shifting only
     68    typeof( ep ) op = 1;                                                                // accumulate odd product
    6969    for ( ; y > 1; y >>= 1 ) {                                                  // squaring exponentiation, O(log2 y)
    70                 if ( (y & 1) == 1 ) po *= pe;                                   // odd ?
    71                 pe *= pe;
    72         } // while
    73     return pe * po;
     70                if ( (y & 1) == 1 ) op *= ep;                                   // odd ?
     71                ep *= ep;
     72        } // for
     73    return ep * op;
    7474} // ?\?
    7575
    76 static inline double ?\?( long int x, signed long y ) { // allow negative exponent
     76static inline double ?\?( long int x, signed long int y ) {     // allow negative exponent
    7777    if ( y >=  0 ) return (double)(x \ (unsigned long int)y);
    7878    else return 1.0 / x \ (unsigned int)(-y);
     
    8080
    8181static inline forall( otype T | { void ?{}( T * this, one_t ); T ?*?( T, T ); double ?/?( double, T ); } )
    82 double ?\?( T x, signed long y ) {
     82double ?\?( T x, signed long int y ) {
    8383    if ( y >=  0 ) return (double)(x \ (unsigned long int)y);
    84     else return 1.0 / x \ (unsigned int)(-y);
     84    else return 1.0 / x \ (unsigned long int)(-y);
    8585} // ?\?
    8686
    87 static inline long int ?\=?( long int * x, unsigned long y ) { *x = *x \ y; return *x; }
    88 static inline long int ?\=?( unsigned long int * x, unsigned long y ) { *x = *x \ y; return *x; }
    89 static inline int ?\=?( int * x, unsigned long y ) { *x = *x \ y; return *x; }
    90 static inline int ?\=?( unsigned int * x, unsigned long y ) { *x = *x \ y; return *x; }
     87static inline long int ?\=?( long int * x, unsigned long int y ) { *x = *x \ y; return *x; }
     88static inline unsigned long int ?\=?( unsigned long int * x, unsigned long int y ) { *x = *x \ y; return *x; }
     89static inline int ?\=?( int * x, unsigned long int y ) { *x = *x \ y; return *x; }
     90static inline unsigned int ?\=?( unsigned int * x, unsigned long int y ) { *x = *x \ y; return *x; }
    9191
    9292// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.