fixed-point

Reproducibility of floating point operation result

半腔热情 提交于 2019-11-28 08:13:35
问题 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

How to improve fixed point square-root for small values

笑着哭i 提交于 2019-11-27 22:59:49
I am using Anthony Williams' fixed point library described in the Dr Dobb's article " Optimizing Math-Intensive Applications with Fixed-Point Arithmetic " to calculate the distance between two geographical points using the Rhumb Line method . This works well enough when the distance between the points is significant (greater than a few kilometers), but is very poor at smaller distances. The worst case being when the two points are equal or near equal, the result is a distance of 194 meters, while I need precision of at least 1 metre at distances >= 1 metre. By comparison with a double

fixed point arithmetics in java with fast performance

做~自己de王妃 提交于 2019-11-27 22:31:51
问题 I need to represent some numbers in Java with perfect precision and fixed number of decimal points after decimal point; after that decimal point, I don't care. (More concretely - money and percentages.) I used Java's own BigDecimal now, but I found out, that it's really slow and it starts to show in my application. So I want to solve it with a "regular" integers and a fixed-point arithmetics (long integers have big enough precision for my purposes). Now, I would think that I am not the first

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

大兔子大兔子 提交于 2019-11-27 20:36:09
问题 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)? 回答1: 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

Fixed Point Arithmetic in C Programming

戏子无情 提交于 2019-11-27 18:23:10
I am trying to create an application that stores stock prices with high precision. Currently I am using a double to do so. To save up on memory can I use any other data type? I know this has something to do with fixed point arithmetic, but I can't figure it out. The idea behind fixed-point arithmetic is that you store the values multiplied by a certain amount, use the multiplied values for all calculus, and divide it by the same amount when you want the result. The purpose of this technique is to use integer arithmetic (int, long...) while being able to represent fractions. The usual and most

Fast fixed point pow, log, exp and sqrt

余生长醉 提交于 2019-11-27 17:24:42
I've got a fixed point class (10.22) and I have a need of a pow, a sqrt, an exp and a log function. Alas I have no idea where to even start on this. Can anyone provide me with some links to useful articles or, better yet, provide me with some code? I'm assuming that once I have an exp function then it becomes relatively easy to implement pow and sqrt as they just become. pow( x, y ) => exp( y * log( x ) ) sqrt( x ) => pow( x, 0.5 ) Its just those exp and log functions that I'm finding difficult (as though I remember a few of my log rules, I can't remember much else about them). Presumably,

storing money amounts in mysql

半城伤御伤魂 提交于 2019-11-27 06:24:35
I want to store 3.50 into a mysql table. I have a float that I store it in, but it stores as 3.5, not 3.50. How can I get it to have the trailing zero? Morfildur Do not store money values as float, use the DECIMAL or NUMERIC type: Documentation for MySQL Numeric Types EDIT & clarification: Float values are vulnerable to rounding errors are they have limited precision so unless you do not care that you only get 9.99 instead of 10.00 you should use DECIMAL/NUMERIC as they are fixed point numbers which do not have such problems. It's not generally a good idea to store money as a float as rounding

C++ fixed point library? [closed]

烂漫一生 提交于 2019-11-27 06:20:37
I am looking for a free C++ fixed point library (Mainly for use with embedded devices, not for arbitrary precision math). Basically, the requirements are: No unnecessary runtime overhead: whatever can be done at compile time, should be done at compile time. Ability to transparently switch code between fixed and floating point, with no inherent overhead. Fixed point math functions. There's no much point using fixed point if you need to cast back and forth in order to take a square root. Small footprint. Any suggestions? flatmush There is an open-source fixed point math library project which can

Oracle Floats vs Number

南楼画角 提交于 2019-11-27 02:13:04
问题 I'm seeing conflicting references in Oracles documentation. Is there any difference between how decimals are stored in a FLOAT and a NUMBER types in the database? As I recall from C, et al, a float has accuracy limitations that an int doesn't have. R.g., For 'float's, 0.1(Base 10) is approximated as 0.110011001100110011001101(Base 2) which equals roughtly something like 0.100000001490116119384765625 (Base 10). However, for 'int's, 5(Base 10) is exactly 101(Base 2). Which is why the following

How to improve fixed point square-root for small values

隐身守侯 提交于 2019-11-26 21:20:03
问题 I am using Anthony Williams' fixed point library described in the Dr Dobb's article " Optimizing Math-Intensive Applications with Fixed-Point Arithmetic " to calculate the distance between two geographical points using the Rhumb Line method. This works well enough when the distance between the points is significant (greater than a few kilometers), but is very poor at smaller distances. The worst case being when the two points are equal or near equal, the result is a distance of 194 meters,