DEV Community

Connie Leung
Connie Leung

Posted on

1

Exponential Operator is Supported on Template

Angular 20 will support exponential operator on template.

The feature is in 20.0.0-next.0; therefore, it can be tested after updating the Angular dependencies to the next version.

ng update @angular/cli --next
ng update @angular/core --next
Enter fullscreen mode Exit fullscreen mode

Demo 1: Apply exponential operator on two numbers

<div class="row">
     <p>Case 1: ** operator applied to two integers.</p>
     <p>{{ a }} ** {{ b }} = {{ a ** b }}</p>
</div>

export class AppComponent {
 a = 2;
 b = 3;
}
Enter fullscreen mode Exit fullscreen mode

The result is evaluated to 8 on the template

Demo 2: The exponential operator is right associately

<div class="row">
    <p>Case 2: ** operator is right associative.</p>
    <p>{{ a }} ** {{ b }} ** {{ c }} = {{ a ** b ** c }}</p>
    <p>{{ a }} ** ({{ b }} ** {{ c }}) = {{ a ** (b ** c) }}</p>
 </div>

export class AppComponent {
 a = 2;
 b = 3;
 c = 2;
}
Enter fullscreen mode Exit fullscreen mode

The result is evaluated to 512 on the template.

Demo 3: Parentheses are required around unary operator when it is the base fo the exponential

<div class="row">
     <p>Case 3: parentheses are required around uary operator when it is the base of the ** operator.</p>
      <p>(-2) ** {{ e }} = {{ (-2) ** e }}</p>
      <p>(-2) ** {{ f }} = {{ (-2) ** f }}</p>
</div>

export class AppComponent {
 e = 3;
 f = 4;
}
Enter fullscreen mode Exit fullscreen mode

The result of the first expression is -8 and the result of the second expression is 16.

References:

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay