Thread: Advanced math in precompiling?

  1. #16
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by TriKri View Post
    Why does it have to be an integral type, I thought you could use any type you wanted when writing templates? I'd like to make it work for floats and doubles as well... :/
    That's just how the language is, nothing you can do about it.

    However it is theoretically doable, if you're prepared to create your own compile time floating point type from scratch. You'll need 3 enums, one for the exponent, one for the mantissa, and one for the sign. Then define the basic operations like shifting, and use those to build addition, then from there you should be able to build multiplication etc... Last of all you need to define a float cast operator.
    Or so I've read once before... I haven't gotten around to trying it, though I've reimplemented run-time floating point numbers like this before.
    So we'll be hearing from you in a month no?

    Oh template-metaprogramming is so fun!!!
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  2. #17
    Algorithm engineer
    Join Date
    Jun 2006
    Posts
    286
    Quote Originally Posted by iMalc View Post
    That's just how the language is, nothing you can do about it.

    However it is theoretically doable, if you're prepared to create your own compile time floating point type from scratch. You'll need 3 enums, one for the exponent, one for the mantissa, and one for the sign. Then define the basic operations like shifting, and use those to build addition, then from there you should be able to build multiplication etc... Last of all you need to define a float cast operator.
    Or so I've read once before... I haven't gotten around to trying it, though I've reimplemented run-time floating point numbers like this before.
    So we'll be hearing from you in a month no?

    Oh template-metaprogramming is so fun!!!
    Hmm ... that seems a little bit to overkill for me even though it seems like a cool thing to do
    Come on, you can do it! b( ~_')

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. advanced math library for linux?
    By Cobras2 in forum Linux Programming
    Replies: 5
    Last Post: 07-18-2005, 12:20 AM
  2. how to use operator+() in this code?
    By barlas in forum C++ Programming
    Replies: 10
    Last Post: 07-09-2005, 07:22 PM
  3. toughest math course
    By axon in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 10-28-2003, 10:06 PM
  4. advanced math problem
    By laasunde in forum Tech Board
    Replies: 62
    Last Post: 10-03-2003, 10:19 PM
  5. advanced math help plz
    By Geo-Fry in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 04-14-2003, 07:01 PM