floating-point

GCC generated assembly for unaligned float access on ARM

陌路散爱 提交于 2021-02-20 17:56:41
问题 Hello I am currently working on a program where I need to process a data blob that contains a series of floats which could be unaligned (and also are sometimes). I am compiling with gcc 4.6.2 for an ARM cortex-a8. I have a question to the generated assembly code: As example I wrote a minimal example: For the following test code float aligned[2]; float *unaligned = (float*)(((char*)aligned)+2); int main(int argc, char **argv) { float f = unaligned[0]; return (int)f; } the compiler (gcc 4.6.2 -

GCC generated assembly for unaligned float access on ARM

三世轮回 提交于 2021-02-20 17:56:12
问题 Hello I am currently working on a program where I need to process a data blob that contains a series of floats which could be unaligned (and also are sometimes). I am compiling with gcc 4.6.2 for an ARM cortex-a8. I have a question to the generated assembly code: As example I wrote a minimal example: For the following test code float aligned[2]; float *unaligned = (float*)(((char*)aligned)+2); int main(int argc, char **argv) { float f = unaligned[0]; return (int)f; } the compiler (gcc 4.6.2 -

How does float guarantee 7 digit precision?

与世无争的帅哥 提交于 2021-02-20 04:23:25
问题 As I know Single-precision floating-point number has 1 bit for sign, 8 bits for exponent and 23 bits for mantissa. I can understand that 7 digit integers fit 23 bit mantissa and don't loose precision but can't understand how a number like 1234567000000000 fits without loose "1,2,3,4,5,6,7" digits, what is the math behind this? 回答1: The IEEE-754 basic 32-bit binary floating-point format only guarantees that six significant decimal digits will survive a round-trip conversion, not seven.

Extracting bits from a float in vba

我是研究僧i 提交于 2021-02-19 08:11:51
问题 How can I extract the bits from a Single variable in vba? For example, I want to extract bits 23 to 30 and place them into the lowest 8 bits of an integer. 回答1: For transferring the bit settings of the short variable to an int , the fastest solution is a 'quick and dirty' CopyMemory approach, as seen here. Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Bytes As Long) Public Sub DoubleToIEEE32(ByVal dValue As Double, ByRef nI1 As

When is integer to floating point conversion lossless?

╄→гoц情女王★ 提交于 2021-02-19 04:35:27
问题 Particularly I'm interested if int32_t is always losslessly converted to double . Does the following code always return true ? int is_lossless(int32_t i) { double d = i; int32_t i2 = d; return (i2 == i); } What is for int64_t ? 回答1: Question: Does the following code always return true? Always is a big statement and therefore the answer is no . The C++ Standard makes no mention whether or not the floating-point types which are known to C++ ( float , double and long double ) are of the IEEE-754

Is IEEE 754-2008 deterministic?

拥有回忆 提交于 2021-02-19 01:31:06
问题 If I start with the same values, and perform the same primitive operations (addition, multiplication, comparision etc.) on double-precision 64-bit IEEE 754-2008 values, will I get the same result, independent of the underlying machine? More concretely: Since ECMAScript 2015 specifies that a number values is primitive value corresponding to a double-precision 64-bit binary format IEEE 754-2008 value can I conclude that the same operations yield the same same result here, independent of the

How does printf extract digits from a floating point number?

浪尽此生 提交于 2021-02-18 22:43:31
问题 How do functions such as printf extract digits from a floating point number? I understand how this could be done in principle. Given a number x , of which you want the first n digits, scale x by a power of 10 so that x is between pow(10, n) and pow(10, n-1) . Then convert x into an integer, and take the digits of the integer. I tried this, and it worked. Sort of. My answer was identical to the answer given by printf for the first 16 decimal digits, but tended to differ on the ones after that.

How does printf extract digits from a floating point number?

孤者浪人 提交于 2021-02-18 22:42:52
问题 How do functions such as printf extract digits from a floating point number? I understand how this could be done in principle. Given a number x , of which you want the first n digits, scale x by a power of 10 so that x is between pow(10, n) and pow(10, n-1) . Then convert x into an integer, and take the digits of the integer. I tried this, and it worked. Sort of. My answer was identical to the answer given by printf for the first 16 decimal digits, but tended to differ on the ones after that.

Different results when adding same doubles in different order

五迷三道 提交于 2021-02-18 20:09:48
问题 Why is the output different when adding same numbers? public class Test { public static void main(String a[]) { double[] x = new double[]{3.9, 4.3, 3.6, 1.3, 2.6}; System.out.println(">>>>>>> " + sum(x)); } public static double sum(double[] d) { double sum = 0; for (int i = 0; i < d.length; i++) { sum += d[i]; } return sum; } } Output is : 15.7 and if I interchange values double[] x = new double[] {2.6, 3.9, 4.3, 3.6, 1.3}; I am getting Output as : 15.700000000000001 How do I get the same

How to quickly pack a float to 4 bytes?

情到浓时终转凉″ 提交于 2021-02-18 12:11:47
问题 I've been looking for a way to store floats on WebGL textures. I've found some solutions on the internet, but those only deal with floats on the [0..1) range. I'd like to be able to store arbitrary floats, and, for that, such a function would need to be extended to also store the exponent (on the first byte, say). I don't quite understand how those work, though, so it is not obvious how to do so. In short: What is an efficient algorithm to pack a float into 4 bytes? 回答1: It's ungodly slow,