Fixed-Point c++ library for download
-
- KVRAF
- 3404 posts since 15 Sep, 2002
What are you blinking about Boro?
-
- KVRist
- Topic Starter
- 59 posts since 22 Feb, 2005 from Italy
Sorry for the late answer, I was very busy with my master graduation these days!
You can convert from a variety of types, including floating point, using something like this:
You have to use a TFix32<n> variable with a suitable n of course, to avoid overflow.
If you create those TFix32 objects on the stack, the conversion will be made at compile time, allowing you to write float constants in your code, although it's to be run on non-fp architectures.
You can also write something like this:
Precision: All of the decimal bits you specified (29) are used
Performance: The conversion is made at compile time
If you are addressing floating point capable architectures, and you want to convert a float to a fixed, let's say:
Precision: All of the decimal bits you specified (30) are used
Performance: The conversion cost is a single float multiplication
Converting fixed point values back to float, double or integer values, costs exactly a float, double division, or an arithmetic shift for the latter:
Hope I satisfied your curiosity, anyway I'm always opened to further discussion! 
Are you talking about precision or performance?mistertoast wrote:How well does it deal with conversions to and from floating point?
You can convert from a variety of types, including floating point, using something like this:
Code: Select all
TFix32<16> a(117); //From int
TFix32<28> b(0.0625f); //From float
TFix32<20> c(-0.75); //From double
TFix32<26> d(1+2.f*0.707f); //ExpressionIf you create those TFix32 objects on the stack, the conversion will be made at compile time, allowing you to write float constants in your code, although it's to be run on non-fp architectures.
You can also write something like this:
Code: Select all
TFix32<29> f29 = 3.141593;Performance: The conversion is made at compile time
If you are addressing floating point capable architectures, and you want to convert a float to a fixed, let's say:
Code: Select all
TFix32<30> f30 = GetFloatInput();Performance: The conversion cost is a single float multiplication
Converting fixed point values back to float, double or integer values, costs exactly a float, double division, or an arithmetic shift for the latter:
Code: Select all
// Conversion #1 - calling conversion method
float f = f30.ToFloat();
// Conversion #2 - using automatic casting
float f = f30;Free VST Plugins at http://ag-works.net/
-
- KVRAF
- 3404 posts since 15 Sep, 2002
You answered my question perfectly. A+.
