# Changeset 697e484 for doc

Ignore:
Timestamp:
Mar 26, 2019, 10:30:42 PM (5 years ago)
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
8a30423
Parents:
7726839
Message:

update exponential documentation

File:
1 edited

### Legend:

Unmodified
 r7726839 %% Created On       : Wed Apr  6 14:53:29 2016 %% Last Modified By : Peter A. Buhr %% Last Modified On : Tue Dec 11 23:19:26 2018 %% Update Count     : 3400 %% Last Modified On : Tue Mar 26 22:10:49 2019 %% Update Count     : 3411 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% As for \Index{division}, there are exponentiation operators for integral and floating types, including the builtin \Index{complex} types. 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). 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$. 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. Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the base cannot be negative. \begin{cfa} sout | 2 ®\® 8u | 4 ®\® 3u | -4 ®\® 3u | 4 ®\® -3 | -4 ®\® -3 | 4.0 ®\® 2.1 | (1.0f+2.0fi) ®\® (3.0f+2.0fi); 256 64 -64 0.015625 -0.015625 18.3791736799526 0.264715-1.1922i 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). Overflow from large exponents or negative exponents return zero. Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the exponent cannot be negative. \begin{cfa} 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 | (1.0f+2.0fi) ®\® (3.0f+2.0fi); 1 1 256 -64 125 0 3273344365508751233 0 0 -0.015625 18.3791736799526 0.264715-1.1922i \end{cfa} Parenthesis are necessary for complex constants or the expression is parsed as ©1.0f+®(®2.0fi \ 3.0f®)®+2.0fi©. The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation versions are available. For returning an integral value, the user type ©T© must define multiplication, ©*©, and one, ©1©; 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. The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation version is available. \begin{cfa} forall( otype OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } ) OT ?®\®?( OT ep, unsigned int y ); forall( otype OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } ) OT ?®\®?( OT ep, unsigned long int y ); \end{cfa} The user type ©T© must define multiplication one, ©1©, and, ©*©. \end{cfa} Essentially, the return type is wrapped around the routine name in successive layers (like an \Index{onion}). While attempting to make the two contexts consistent is a laudable goal, it has not worked out in practice. 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: \begin{quote} 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} \end{quote} \CFA provides its own type, variable and routine declarations, using a different syntax.