Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,749 members, 7,817,080 topics. Date: Saturday, 04 May 2024 at 03:45 AM

Integer Types Should Inherit From ... - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Integer Types Should Inherit From ... (935 Views)

What Exactly Do Modifier Types In C++ Do? More Emphasis On Integer Modifiers / Reverse Python Integer Using Reverse_int (2) (3) (4)

(1) (Reply)

Integer Types Should Inherit From ... by asalimpo(m): 10:06pm On Dec 01, 2017
Actually integer types should be descendants of Doubles. Y?
Because all integers can be expressed as double types, just tack a '.0' to it and it becomes a double.
Also mathematically, integers are
subsets of doubles (i.e rationals).
But in most oop languages, integers are separate entities directly descending from abstract class Number/or Real same as Doubles.
This shouldnt be,it's a design flaw.

if i were to architect the heirarchy,
Long Types (actually integers) would
descend from doubles,
which will descend from Real (Real numbers)
which will descend from Number.
Re: Integer Types Should Inherit From ... by Olyboy16(m): 1:19pm On Dec 02, 2017
asalimpo:

Actually integer types should be descendants of Doubles. Y?
Because all integers can be expressed as double types, just tack a '.0' to it and it becomes a double.
Also mathematically, integers are
subsets of doubles (i.e rationals).
But in most oop languages, integers are separate entities directly descending from abstract class Number/or Real same as Doubles.
This shouldnt be,it's a design flaw.

if i were to architect the heirarchy,
Long Types (actually integers) would
descend from doubles,
which will descend from Real (Real numbers)
which will descend from Number.
so if integers "inherit" from double(which is a scientific taboo), how many bits would then store an int? and how would you suppose memory registers would handle this? also with respect to performance analysis, how would you suppose compilers differentiate an integer pointer from a double one?
Re: Integer Types Should Inherit From ... by asalimpo(m): 9:09pm On Dec 02, 2017
Olyboy16:

so if integers "inherit" from double(which is a scientific taboo), how many bits would then store an int? and how would you suppose memory registers would handle this? also with respect to performance analysis, how would you suppose compilers differentiate an integer pointer from a double one?
I dont know which grammer u are speaking there.
In ur favorite oop language, doubles can hold integers.
Which means, doubles are the parent class of integers and will always be conceptually.
The designers of the language should have just expressed this relationship architecturally instead of
spin of integers as separate entities.
Scientifically what? Mathematically, the set Rationals, contains the set Integers.
which puts paid to the argument that integers descend from Rationals,the same set Doubles (which are mathematically rationals descend from).
Creating a more streamlined architecture will not affect the underlying implementation at all.
Cuz underneath,it's all bits - 1s and 0s. If strings can be resolved at that level any other hierarchy can.

class Number <abstract>
|
|
Real <abstract>
|
Rational<abstract> , IRRational<abstract>
| |
Rational, Pi,e, squareRootOf2,3 etc
Integers
|
NegativeInts,PositiveInt,Zero
or
NegativeInts, NonNegativeInts (positives and zero).

The Rational class will include the doubles and floating points.

You could then initialize a rational with any of its subclasses.
e.g
Rational n = new Rational(<int>wink
or
Rational n = new Rational(<double>wink
or
Rational n = ne Rational(<nonNegInt>wink


I'm assuming rational is used instead of the name ,double or floating point.

Consider that in java, a BigDecimal can be initialized with a BigInteger.
e.g
BigInteger b = new BigInteger(1000000000);
BigDecimal n = new BigDecimal(b);

So BigDecimals are the supertypes of bigIntegers,which underscores what i'm trying to say.
That integers descend from doubles / rationals.

(1) (Reply)

Programmers In Warri... Come In / Learn How To Code Android, Build Web Service With PHP And How To Host A Website. / I Need Help With Local Host Configuration

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 17
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.