fixed-point

fixed point multiplication without 64 bit temporary

不羁的心 提交于 2019-12-01 06:52:50
Hi I'm implementing some fixed point math stuff for embedded systems and I'm trying to do the multiplication of two 16.16 fixed point numbers without creating a 64bit temporary. So far here is the code I came up with that generates the least instructions. int multiply(int x, int y){ int result; long long temp = x; temp *= y; temp >>= 16; result = temp; return result; } the problem with this code is that it uses a temporary 64 bit integer which seem to generate bad assembly code. I'm trying to make a system that uses two 32 bit integers instead of a 64 bit one. Anyone know how to do this? Think

Signed & unsigned integer multiplication

☆樱花仙子☆ 提交于 2019-11-30 22:26:12
In fixed point math I use a lot of 16bit signals and perform multiplication with 32bit intermediate results. For example: int16_t a = 16384; //-1.0q14 or 1.0*2^14 int16_t b = -24576; // -1.4q14 or 1.4*2^14 int16_t c; // result will be q14 c = (int16_t)(((int32_t)a * (int32_t)b)>>14); Lets say a is a q14 number then c with have the same scaling as b. This is fine and works for unsigned as well as signed arithmetic. The question is: What happens if I were to mix types? For example if I know the multiplier "a" is always going to range from 0.0 to 1.0, it is tempting to make it an unsigned int q15

Signed & unsigned integer multiplication

两盒软妹~` 提交于 2019-11-30 05:43:36
问题 In fixed point math I use a lot of 16bit signals and perform multiplication with 32bit intermediate results. For example: int16_t a = 16384; //-1.0q14 or 1.0*2^14 int16_t b = -24576; // -1.4q14 or 1.4*2^14 int16_t c; // result will be q14 c = (int16_t)(((int32_t)a * (int32_t)b)>>14); Lets say a is a q14 number then c with have the same scaling as b. This is fine and works for unsigned as well as signed arithmetic. The question is: What happens if I were to mix types? For example if I know the

Converting floating point to fixed point

耗尽温柔 提交于 2019-11-29 20:28:56
In C++, what's the generic way to convert any floating point value (float) to fixed point (int, 16:16 or 24:8)? EDIT: For clarification, fixed-point values have two parts to them: an integer part and a fractional part. The integer part can be represented by a signed or unsigned integer data type. The fractional part is represented by an unsigned data integer data type. Let's make an analogy with money for the sake of clarity. The fractional part may represent cents -- a fractional part of a dollar. The range of the 'cents' data type would be 0 to 99. If a 8-bit unsigned integer were to be used

Compiling *.vhdl into a library, using Altera Quartus II

安稳与你 提交于 2019-11-29 14:57:56
I am trying to use 'Floating point and Fixed point package' as a part of my filter design in VHDL. I am using Altera Quartus II as the development environment. I downloaded the file package from the website: http://www.vhdl.org/fphdl/ , now available at http://web.archive.org/web/20160305202256/http://www.vhdl.org/fphdl/ In their user guide, below is mentioned: 'fixed_float_types_c.vhdl', 'fixed_pkg_c.vhdl' and 'float_pkg_c.vhdl' should be compiled into a library called "ieee_proposed". However, I do not exactly know how I can compile the mentioned *.vhdl files into a library using Altera

Reproducibility of floating point operation result

我怕爱的太早我们不能终老 提交于 2019-11-29 14:27:06
Is it possible for an floating-point arithmetic operation to yield different results on different CPUs? By CPUs i mean all of x86 and x64. And by different results i mean even if only a single least important bit is different.. I need to know if I can use floating point operations on project where it's vital to have exactly the same results corresponding to same input on different machines. Edit: added c++ tag. Also to clarify: I need reproducible results run-time. I wouldn't expect identical results from different compilations. In the gaming industry this is referred to as deterministic

Doing exact real number arithmetic with PHP

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 04:52:09
What is fastest and most easy way of making basic arithmetic operations on strings representing real numbers in PHP? I have a string representing MySQL's DECIMAL value on which I want to operate and return the result to a database after that. I would like to avoid errors introduced by floating-point real number representation. Is there some standard library like Python's decimal? Are there any FOSS libraries you can recommend? Regards You could use the BC math functions: http://www.php.net/manual/en/ref.bc.php Or the GMP functions, although they seem to be integer only. http://www.php.net

How do I convert a floating point C code to fixed point?

心已入冬 提交于 2019-11-28 19:41:22
I have a C code which uses doubles. I want to be able to run the code on a DSP ( TMS320 ). But the DSP doesn't support doubles, only fixed-point numbers. What is the best way to convert the code into fixed-point? Is there a good C library for fixed-point numbers (implemented as integers)? TI provides a fixed-point library called "IQmath": http://focus.ti.com/lit/sw/sprc990/sprc990.pdf Converting involves analyzing your current code - for each variable you need to know what range it can hold, and what precision it needs. Then you can decide which type to store it in. IQMath provides types from

Converting floating point to fixed point

拟墨画扇 提交于 2019-11-28 16:33:53
问题 In C++, what's the generic way to convert any floating point value (float) to fixed point (int, 16:16 or 24:8)? EDIT: For clarification, fixed-point values have two parts to them: an integer part and a fractional part. The integer part can be represented by a signed or unsigned integer data type. The fractional part is represented by an unsigned data integer data type. Let's make an analogy with money for the sake of clarity. The fractional part may represent cents -- a fractional part of a

Json in C++: Parse a number as a string to avoid floating-point inaccuracy

两盒软妹~` 提交于 2019-11-28 10:33:40
问题 I'm dealing with a cryptocurrency RPC and receiving json data as follows: { ... "amount": 1.34000000, "confirmations": 230016, "spendable": true, "solvable": true ... } Using Jsoncpp library or json11 gets the number parsed to a double . When this happens, the result is: 1.3400000000000001 , due to double accuracy problems. In general this is catastrophic to financial transations and unacceptable. I already have a fixed-point library that can take a valid string and treat it as an integer