Floating Point Constants

Started by
11 comments, last by sundersoft 11 years, 8 months ago
I used to do stuff like this, but these days I think it's a little bit pointless. What normally happens is that 99.9% of the time you're fine with floats, and then every so often you need to find a bit more precision. Having a blanket float/double type, doesn't really work that well in practice I find. It just means that 'real' will always be a float, and you'll end up using double as and when you need it. That slightly annoying reality, makes a 'real' type a bit superflous imho. Just my 2 cents....
Advertisement
Very true, I wouldn't recommend it for everyone.

It's more of an experiment but it's not much more trouble than not doing it (once the changes are made to existing code) so I guess it's a bit of future proofing.
IMO you should be using templates if you need to write code that works with any type. This allows you to use multiple types and change them later without affecting existing code. Besides float and double, it's also possible that you may use one of the integer types, complex, a quaternion type, a vector or matrix type, etc. For example, if you have a generic vector type then you can use vec<unsigned char, 4> or vec_4<unsigned char> to store image data and manipulate it in a convenient manner (although you may also have to implement casts).

This topic is closed to new replies.

Advertisement