fixed-point

Numerical Conversion in C/C++

有些话、适合烂在心里 提交于 2021-01-29 18:19:25
问题 I need to convert a C/C++ double to a 64 bit two's complement, where the Radix point is at bit number 19 (inclusive). This means that for the format I want to convert to 0x0000 0000 0010 0000 is the number 1 0xFFFF FFFF FFF0 0000 is the number -1 0x0000 0000 0000 0001 is 0.95 x 10^-6 0xFFFF FFFF FFFF FFFF is -0.95 x 10^-6 So far I've though about using the modf function from the C standard library, but that doesn't really cover my needs. I've also looked at some type conversion classes in

implementing a hash table-like data structure with floating point keys where values within a tolerance are binned together

别来无恙 提交于 2020-12-12 06:50:40
问题 I need an associative data structure with floating point keys in which keys with nearly equal values are binned together. I'm working in C++ but language doesnt really matter. Basically my current strategy is to only handle single precision floating point numbers use an unordered_map with a custom key type define the hash function on the key type as a. given float v divide v by some tolerance, such as 0.0005, at double precision, yielding k . b. cast k to a 64 bit integer yielding ki c.

implementing a hash table-like data structure with floating point keys where values within a tolerance are binned together

蓝咒 提交于 2020-12-12 06:49:28
问题 I need an associative data structure with floating point keys in which keys with nearly equal values are binned together. I'm working in C++ but language doesnt really matter. Basically my current strategy is to only handle single precision floating point numbers use an unordered_map with a custom key type define the hash function on the key type as a. given float v divide v by some tolerance, such as 0.0005, at double precision, yielding k . b. cast k to a 64 bit integer yielding ki c.

How do you multiply two fixed point numbers?

|▌冷眼眸甩不掉的悲伤 提交于 2020-05-15 06:21:06
问题 I am currently trying to figure out how to multiply two numbers in fixed point representation. Say my number representation is as follows: [SIGN][2^0].[2^-1][2^-2]..[2^-14] In my case, the number 10.01000000000000 = -0.25 . How would I for example do 0.25x0.25 or -0.25x0.25 etc? Hope you can help! 回答1: Multiply into a larger sized variable, and then right shift by the number of bits of fixed point precision. 回答2: You should use 2's complement representation instead of a seperate sign bit. It

How to reverse fixed point binary log algorithm for fractional power of 2?

陌路散爱 提交于 2020-04-30 06:28:19
问题 I found a fast binary logarithm algorithm for fixed points in an answer to this question: Fast fixed point pow, log, exp and sqrt, based on an algorithm by Clay S. Turner. Is it possible to "reverse" this to calculate fractional powers of two? e.g: // log2(3) = 1.5849609375 log2fix(196608, 16) == 103872 pow2fix(103872, 16) == 196608 Here's the code from Dan Moulding: #include <errno.h> #include <stddef.h> #include "log2fix.h" int32_t log2fix (uint32_t x, size_t precision) { int32_t b = 1U <<

Removing slow int64 division from fixed point atan2() approximation

大兔子大兔子 提交于 2020-01-24 10:10:48
问题 I made a function to compute a fixed-point approximation of atan2(y, x). The problem is that of the ~83 cycles it takes to run the whole function, 70 cycles (compiling with gcc 4.9.1 mingw-w64 -O3 on an AMD FX-6100) are taken entirely by a simple 64-bit integer division! And sadly none of the terms of that division are constant. Can I speed up the division itself? Is there any way I can remove it? I think I need this division because since I approximate atan2(y, x) with a 1D lookup table I

Fixed point multiply/divide for 15.16 numbers

霸气de小男生 提交于 2020-01-14 05:31:23
问题 I am looking for an algorithm to multiply and divide fixed point 15.16 numbers. I already have addition and subtraction. Those were easy - simple 32-bit add and subtract. With multiply and divide, I can also add many trigonometric and exponential/log functions. And I think I can deal with just multiply, as my library has a reciprocal function and I can use that to implement division: a * (1/b) = a / b . But a 32-bit multiply does not work as it ignores the radix point. I am working on a 16

fixed point singular value decomposition in c/c++ [closed]

流过昼夜 提交于 2020-01-07 09:44:39
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I am looking for some c/c++ libraries to do fixed point singular value decomposition or eigenvalue decomposition. Do you know any libraries or any pointers to existing codes? Thanks 回答1: There is a good answer to your question in this thread: Single Value Decomposition implementation C++ Also, @Bathsheba is

fixed point singular value decomposition in c/c++ [closed]

时光怂恿深爱的人放手 提交于 2020-01-07 09:44:13
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I am looking for some c/c++ libraries to do fixed point singular value decomposition or eigenvalue decomposition. Do you know any libraries or any pointers to existing codes? Thanks 回答1: There is a good answer to your question in this thread: Single Value Decomposition implementation C++ Also, @Bathsheba is