base numeric type?

  • Thread starter Thread starter Arthur Dent
  • Start date Start date
A

Arthur Dent

Hi all...

I'm playing around experimenting with Extensions and R&D'ing what's new.

There's a procedure I would like to add to numbers, and I was wondering, is
there any "base" number type, that I could put an extension on, as opposed
to manually adding it to all the numeric types...
decimal, double, single, long, short, etc... ??

Cheers!
Arthur Dent.
 
Arthur Dent said:
Hi all...

I'm playing around experimenting with Extensions and R&D'ing what's
new.

There's a procedure I would like to add to numbers, and I was
wondering, is there any "base" number type, that I could put an
extension on, as opposed to manually adding it to all the numeric
types...
decimal, double, single, long, short, etc... ??

I'm also playing with extensions currently, so still a begginer, but...

As the basic types (decimal etc) are treated specially, i.e. not like any
other Structure or Class, the variables must be declared explicitly as the
specific type in order to give VB the possibility to handle them like these
native types.

So, what's left are the common interfaces like IComparable or IFormattable.

Method overloading is still an option but would require you treating each
type individually, which you want to avoid.

Constraints (Of T As {...}) are not an option either because Single etc is
not allowed with constraints. Wouldn't be of much use anyways.


Most important last: What are you trying to do with these types?


Armin
 
Arthur,

What is wrong with the for all base type object, normal can from that any
numeric type be converted as long as it does not conflict with the receiving
field? Convert from int to double goes, from double to integer can conflict.

I understand that it is not a direct answer on your question, however I use
in that often the sample of the car I had. It had a square steeringwheel
(Austin Allegro). I found it great, it was something different and probably
from the future. In fact it had only problems; To much to tell here. Square
wheels seldom function, however they are invented again and again and again.

And don't tell converting takes time, all new steering wheels thake behind
the scene probably much more time.

Just my idea reading your message

Cor
 
Most important last: What are you trying to do with these types?

Well, for example, take a inanely simple numeric function, "IsPositive". I
know this is not something you'd actually code, because it is SO simple, but
as an example.

I'd like to take my new function, and be able to do something akin to

<Extension()> Public Function IsPositive(target As anyNumericType) As
Boolean

As opposed to having to do this...

<Extension()> Public Function IsPositive(target As Short) As Boolean
<Extension()> Public Function IsPositive(target As Integer) As Boolean
<Extension()> Public Function IsPositive(target As Long) As Boolean
<Extension()> Public Function IsPositive(target As Single) As Boolean
<Extension()> Public Function IsPositive(target As Double) As Boolean
<Extension()> Public Function IsPositive(target As Decimal) As Boolean

It would be very nice if all the "number" types did implement some common
INumber interface, but as far as I know, they don't, do they?
 
Arthur Dent said:
Well, for example, take a inanely simple numeric function,
"IsPositive". I know this is not something you'd actually code,
because it is SO simple, but as an example.

I'd like to take my new function, and be able to do something akin
to

<Extension()> Public Function IsPositive(target As
anyNumericType) As Boolean

As opposed to having to do this...

<Extension()> Public Function IsPositive(target As Short) As
Boolean <Extension()> Public Function IsPositive(target As
Integer) As Boolean <Extension()> Public Function
IsPositive(target As Long) As Boolean <Extension()> Public
Function IsPositive(target As Single) As Boolean <Extension()>
Public Function IsPositive(target As Double) As Boolean <Extension()>
Public Function IsPositive(target As Decimal) As
Boolean

It would be very nice if all the "number" types did implement some
common INumber interface, but as far as I know, they don't, do they?

No, only those that you see in the object browser.

Why not simply use ">0" in this case (without using Extensions)? Or
Math.Sign which is overloaded but already there. What else do you want to do
with "target"?


Armin
 
Back
Top