Thread: About writing a custom datatype

  1. #1
    Registered User
    Join Date
    Sep 2018

    About writing a custom datatype

    I know that by using classes and the char-datatype, we can represent our own datatype and overload operators for it. Say arbitrary large integers.

    But, however, this takes 1 byte per digit which is really really bad.

    So would it be possible to allocate n bytes of memory and use all these bytes of memory to represent a number in C++..? Note that the number could be large enough that it cannot be represented by standard types as they do not have enough bytes to represent the number.

    So that 10 bytes would let you represent 2^10 numbers instead of 10digits?

    Because that's how interpreters support arbitrary large numbers right, they allocate enough memory to store the number if it's larger than a particular number.

  2. #2
    Registered User
    Join Date
    May 2009
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Dec 2017
    For C++, the boost library is probably better. It can use GMP under the hood.
    Philosophy is a battle against the bewitchment of our intelligence by means of language. - Wittgenstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 09-23-2012, 03:06 PM
  2. datatype bit?
    By MK27 in forum C Programming
    Replies: 3
    Last Post: 02-05-2009, 01:56 PM
  3. Writing to custom resources
    By Kirdra in forum Windows Programming
    Replies: 1
    Last Post: 01-21-2009, 05:08 AM
  4. Datatype
    By ssharish2005 in forum C Programming
    Replies: 6
    Last Post: 08-04-2008, 12:53 PM
  5. DataType* MyVar;
    By GetAGrip in forum C Programming
    Replies: 3
    Last Post: 01-30-2006, 01:29 PM

Tags for this Thread