Why doesn't C# have a power operator?

Published 07 March 04 12:54 PM

Some languages provide a power operator, so one can write something like:

float result = value^2;

rather than having to resort to calling. We don't have one in C#.

It would be possible to add a power operator to the language, but performing this operation is a fairly rare thing to do in most programs, and it doesn't seem justified to add an operator when calling Math.Pow() is simple.

I also worry a bit about the implementation of such operators. It seems likely that most compilers would translate my example above to:

float result = Math.Pow(value, 2.0);

That works, but has the unfortunate side effect of replacing a simple multiplication (value * value) with a complex trig function.

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Roy J. Salisbury said on March 7, 2004 4:18 PM:
# Christian Nagel's OneNotes said on March 7, 2004 4:23 PM:
# RebelGeekz said on December 28, 2004 4:55 AM:
[http://itpeixun.51.net/][http://aissl.51.net/][http://kukuxz003.freewebpage.org/][http://kukuxz001.51.net/][http://kukuxz003.51.net/][http://kukuxz005.51.net/][http://kukuxz002.51.net/][http://kukuxz004.freewebpage.org/][http://kukuxz007.51.net/][http://kukuxz001.freewebpage.org/][http://kukuxz006.51.net/][http://kukuxz002.freewebpage.org/][http://kukuxz004.51.net/][http://kukuxz008.51.net/][http://kukuxz009.51.net/][http://kukuxz005.freewebpage.org/][http://kukuxz006.freewebpage.org/][http://kukuxz007.freewebpage.org/][http://kukuxz009.freewebpage.org/]
# Christian Nagel's OneNotes said on January 14, 2005 2:58 AM:
# C Frequently Asked Questions Why doesn t C have a power operator | Cellulite Creams said on June 8, 2009 10:49 PM:

PingBack from http://cellulitecreamsite.info/story.php?id=9480

# C Frequently Asked Questions Why doesn t C have a power operator | alternative dating said on June 17, 2009 4:10 AM:

PingBack from http://topalternativedating.info/story.php?id=12859

# Gary said on October 14, 2009 3:58 AM:

I think having a power operator in C# would be really useful personally.

http://www.createwebspace.co.uk

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

This Blog

Syndication

Page view tracker