Topic: ANSI/net && Power Operator !


Author: maxtal@extro.ucc.su.OZ.AU (John (MAX) Skaller)
Date: Tue, 30 Jun 1992 16:13:18 GMT
Raw View
In article <1992Jun29.175015.19642@dg-rtp.dg.com> welshm@mirage.rtp.dg.com (Matt Welsh) writes:
>In article <BqM2JG.8Ds@news.cso.uiuc.edu> tiller@solace.me.uiuc.edu (Mike Tiller) writes:
>>I would support a newsgroup for discussion of these ANSI issues.
>>
>>I find it very difficult to figure out why there isn't a power
>>operator implemented for C++.  If something as simple as a power
>>operator can't be implemented then how much faith are we to
>>have in the ANSI process.  All the proposals I have seen so far
>>have been good sound proposals requiring a little polishing
>>around the edges.
>
>You can define your own power operator; can you not? This is the point
>behind operator overloading-- you can define the operator for any type
>that you need it.

 No, you cannot overload operators that take only
built in types for arguments. Pow would be such an operator.

>I think the operator is not defined by the standard
>because methods for raising things to powers are so machine-dependent,
>and raising something to a power is not generally something defined by
>the CPU-- it's defined either by emulation software or an FPU.

 The same is true for all the other operators.
For example, right shift on 'int' is implementation dependent
because there is no match between negative numbers and bit patterns
required by the standard. And the result of a%b is not defined
either (if one or more of a, b are negative).

 I think the actually numerical value of a!b is of less
consequence than having the operator. If it were just defined
to map to pow(a,b) like a macro, that would be a big advantage,
especially if you could then overload pow.

 [In other words, an alternative proposal is that
binary ! be allowed in the language, and that it can be
overloaded *even* for standard types. Does anyone like
this idea? The original justification for not
overloading existing operators  for standard
argument types does not apply in then]

>
>Matt Welsh     welshm@dg-rtp.dg.com
>UNIX-SQA, Data General Corporation RTP        Office: (919)248-6070
>  "You're a jerk, Dent. A complete kneebiter."


--
;----------------------------------------------------------------------
        JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
 Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------




Author: maxtal@extro.ucc.su.OZ.AU (John (MAX) Skaller)
Date: Tue, 30 Jun 1992 16:28:21 GMT
Raw View
In article <MATT.92Jun29151100@physics.berkeley.edu> matt@physics.berkeley.edu writes:
>In article <1992Jun29.175015.19642@dg-rtp.dg.com> welshm@mirage.rtp.dg.com (Matt Welsh) writes:
>
>> You can define your own power operator; can you not?
>
>There really is no way to have an exponentiation operator unless it is
>added to the language.  This is a trivial enough addition, and
>important enough to some people, that I see no reason not to do it.
>--

 There is an alternative approach to adding operator! as an
exponentiation operator.

 Add operator! to the language, leave it undefined,
and allow it to be overloaded *even* for standard types.
Although no class is involved, it cannot break existing code.
[It must be given the appropriate precedence and associativity]

[Optionally, if you don't define it, the compiler can supply
an implementation dependent definition]


--
;----------------------------------------------------------------------
        JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
 Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------