Overriding Arithmetic Operators (help!) 
Author Message
 Overriding Arithmetic Operators (help!)

Dear friends,

I'm working on astronomy classes. Some numbers do not 'fit' on the
Decimal data type (are too large or need better precision).

So I implemented split code to deal with numbers of any size I want, but
I dont like using functions like this:

   lnAlfa = Sum(lnBeta, lnGama)         ' a = b + g
   lnDelta = Mul(lnAlfa, lnEpsilon)     ' d = a * e

When the functions are alot more complex, things become wild   :-(
that's why we all use operators.

Can I override the arithmetic operators (+,-,*,/)? Or do any other trick
so I can simple write:

   lnAlfa = lnBeta + lnGama
   lnDelta = lnAlfa * lnEpsilon

If you can help me, you deserve a kiss :-) and I thank you in advance.

Kind regards,
Betty

*** Sent via Developersdex http://www.*-*-*.com/ ***
Don't just participate in USENET...get rewarded for it!



Sun, 30 Jan 2005 10:46:09 GMT  
 Overriding Arithmetic Operators (help!)
I don't think VB.Net can do this, though C# probably can (and I've
just about exhausted my knowledge of C# in that statement <g>). One
obvious suggestion would be to replace your operators with functions
which you could then overload (e.g. fnSum, fnDivide, etc.).

--
Paul Thornett


Quote:
> I'm working on astronomy classes. Some numbers do not 'fit' on the
> Decimal data type (are too large or need better precision).

> So I implemented split code to deal with numbers of any size I want,
but
> I dont like using functions like this:

>    lnAlfa = Sum(lnBeta, lnGama)         ' a = b + g
>    lnDelta = Mul(lnAlfa, lnEpsilon)     ' d = a * e

> When the functions are alot more complex, things become wild   :-(
> that's why we all use operators.

> Can I override the arithmetic operators (+,-,*,/)? Or do any other
trick
> so I can simple write:

>    lnAlfa = lnBeta + lnGama
>    lnDelta = lnAlfa * lnEpsilon

> If you can help me, you deserve a kiss :-) and I thank you in

advance.


Sun, 30 Jan 2005 14:56:34 GMT  
 Overriding Arithmetic Operators (help!)


Quote:
> Dear friends,

> I'm working on astronomy classes. Some numbers do not 'fit' on the
> Decimal data type (are too large or need better precision).

> So I implemented split code to deal with numbers of any size I want, but
> I dont like using functions like this:

>    lnAlfa = Sum(lnBeta, lnGama)         ' a = b + g
>    lnDelta = Mul(lnAlfa, lnEpsilon)     ' d = a * e

> When the functions are alot more complex, things become wild   :-(
> that's why we all use operators.

> Can I override the arithmetic operators (+,-,*,/)? Or do any other trick
> so I can simple write:

>    lnAlfa = lnBeta + lnGama
>    lnDelta = lnAlfa * lnEpsilon

> If you can help me, you deserve a kiss :-) and I thank you in advance.

> Kind regards,
> Betty

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

You can't do it. I think operator overloading is planned for the next
version of VB .NET. Otherwise you have to use C#. (Or MC++, which I'm sure
you would avoid.)

Eiffel .NET also has operator overloading.

Kevin



Sun, 30 Jan 2005 18:43:36 GMT  
 Overriding Arithmetic Operators (help!)
I had a similar issue with a function of time class that I
have been working on.  Operator overloading would be great
but not available yet for VB.  Functions instead of
operators really obscure the code so I am anxiously
waiting for operator overloading in VB.

Keith

Quote:
>-----Original Message-----
>Dear friends,

>I'm working on astronomy classes. Some numbers do
not 'fit' on the
>Decimal data type (are too large or need better
precision).

>So I implemented split code to deal with numbers of any
size I want, but
>I dont like using functions like this:

>   lnAlfa = Sum(lnBeta, lnGama)         ' a = b + g
>   lnDelta = Mul(lnAlfa, lnEpsilon)     ' d = a * e

>When the functions are alot more complex, things become
wild   :-(
>that's why we all use operators.

>Can I override the arithmetic operators (+,-,*,/)? Or do
any other trick
>so I can simple write:

>   lnAlfa = lnBeta + lnGama
>   lnDelta = lnAlfa * lnEpsilon

>If you can help me, you deserve a kiss :-) and I thank
you in advance.

>Kind regards,
>Betty

>*** Sent via Developersdex http://www.developersdex.com
***
>Don't just participate in USENET...get rewarded for it!
>.



Sun, 30 Jan 2005 22:41:53 GMT  
 Overriding Arithmetic Operators (help!)
Don't get too anxious.

I was looking forward to this, too.  Then I discovered that it's not
supported.

"No Problem!"  Says I.  "I'll just implement this class in a C# class
library.  That way I can overload the operators.  Ain't cross-language
development grand?!?!"

So, I spent about 1-1/2 days recoding a class in C# with overloaded
operators and implicit/explicit conversion overloads.   (I'm not normally a
C/C++/C# developer, so I work a little slower with the syntax.)

I reference the C# project from my VB project, instantiate an object of the
class, and try to increment it by 1 (+= 1).

I get some error message about there not being a '+' operator defined for
the class.

The class works perfectly fine in a C# app.

:-(

--
Toby Herring
Software Architects, Inc.
MCDBA, MCSD


Quote:
> I had a similar issue with a function of time class that I
> have been working on.  Operator overloading would be great
> but not available yet for VB.  Functions instead of
> operators really obscure the code so I am anxiously
> waiting for operator overloading in VB.

> Keith

> >-----Original Message-----
> >Dear friends,

> >I'm working on astronomy classes. Some numbers do
> not 'fit' on the
> >Decimal data type (are too large or need better
> precision).

> >So I implemented split code to deal with numbers of any
> size I want, but
> >I dont like using functions like this:

> >   lnAlfa = Sum(lnBeta, lnGama)         ' a = b + g
> >   lnDelta = Mul(lnAlfa, lnEpsilon)     ' d = a * e

> >When the functions are alot more complex, things become
> wild   :-(
> >that's why we all use operators.

> >Can I override the arithmetic operators (+,-,*,/)? Or do
> any other trick
> >so I can simple write:

> >   lnAlfa = lnBeta + lnGama
> >   lnDelta = lnAlfa * lnEpsilon

> >If you can help me, you deserve a kiss :-) and I thank
> you in advance.

> >Kind regards,
> >Betty



Sun, 30 Jan 2005 23:13:09 GMT  
 Overriding Arithmetic Operators (help!)


Quote:
> Don't get too anxious.

> I was looking forward to this, too.  Then I discovered that it's not
> supported.

I'm pretty sure it will be in the next version.


Mon, 31 Jan 2005 04:02:12 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Passing an Arithmetic Operator as a variable

2. Operator Overrides

3. operator override question

4. operator override question

5. Arithmetic Overflow!! Help

6. Possible bug in VB double-precision arithmetic/comparison operators?

7. HELP: Overriding Control Event handler(s)

8. Help - can't override win98 system sounds!

9. HELP: Overriding Control Event handler(s)

10. Overriding IE help

11. arithmetic problem in a VB module

12. Access: missing operator, HELP

 

 
Powered by phpBB® Forum Software