floating-point

How to compute the digits of an irrational number one by one?

家住魔仙堡 提交于 2020-12-06 16:55:23
问题 I want to read digit by digit the decimals of the sqrt of 5 in C. The square root of 5 is 2,23606797749979..., so this'd be the expected output: 2 3 6 0 6 7 9 7 7 ... I've found the following code: #include<stdio.h> void main() { int number; float temp, sqrt; printf("Provide the number: \n"); scanf("%d", &number); // store the half of the given number e.g from 256 => 128 sqrt = number / 2; temp = 0; // Iterate until sqrt is different of temp, that is updated on the loop while(sqrt != temp){ /

How to convert an integer to a floating point value in x86 ASM?

牧云@^-^@ 提交于 2020-12-06 04:20:13
问题 I need to multiply an integer (two's compliment) by a floating point constant. Here is what I have: .data pi dd 3.14 int dd 0ah .code fld pi ??? fmul ST(1), ST How can I convert int to a floating point value for multiplying against pi ? 回答1: You need the fild instruction. Here's one reference: http://www.website.masmforum.com/tutorials/fptute/fpuchap5.htm 回答2: Using the x86 FPU is really outdated now and way slower than SSE/AVX/etc. Better to use at least SSE with cvtdq2ps doc ex: .data int

How to convert an integer to a floating point value in x86 ASM?

最后都变了- 提交于 2020-12-06 04:17:32
问题 I need to multiply an integer (two's compliment) by a floating point constant. Here is what I have: .data pi dd 3.14 int dd 0ah .code fld pi ??? fmul ST(1), ST How can I convert int to a floating point value for multiplying against pi ? 回答1: You need the fild instruction. Here's one reference: http://www.website.masmforum.com/tutorials/fptute/fpuchap5.htm 回答2: Using the x86 FPU is really outdated now and way slower than SSE/AVX/etc. Better to use at least SSE with cvtdq2ps doc ex: .data int

Exact value of a floating-point number as a rational

帅比萌擦擦* 提交于 2020-12-01 11:39:11
问题 I'm looking for a method to convert the exact value of a floating-point number to a rational quotient of two integers, i.e. a / b , where b is not larger than a specified maximum denominator b_max . If satisfying the condition b <= b_max is impossible, then the result falls back to the best approximation which still satisfies the condition. Hold on. There are a lot of questions/answers here about the best rational approximation of a truncated real number which is represented as a floating

Exact value of a floating-point number as a rational

扶醉桌前 提交于 2020-12-01 11:38:21
问题 I'm looking for a method to convert the exact value of a floating-point number to a rational quotient of two integers, i.e. a / b , where b is not larger than a specified maximum denominator b_max . If satisfying the condition b <= b_max is impossible, then the result falls back to the best approximation which still satisfies the condition. Hold on. There are a lot of questions/answers here about the best rational approximation of a truncated real number which is represented as a floating

Exact value of a floating-point number as a rational

£可爱£侵袭症+ 提交于 2020-12-01 11:35:08
问题 I'm looking for a method to convert the exact value of a floating-point number to a rational quotient of two integers, i.e. a / b , where b is not larger than a specified maximum denominator b_max . If satisfying the condition b <= b_max is impossible, then the result falls back to the best approximation which still satisfies the condition. Hold on. There are a lot of questions/answers here about the best rational approximation of a truncated real number which is represented as a floating

Is there a C equivalent of C#'s decimal type?

别说谁变了你拦得住时间么 提交于 2020-11-29 04:35:59
问题 In relation to: Convert Decimal to Double Now, I got to many questions relating to C#'s floating-point type called decimal and I've seen its differences with both float and double , which got me thinking if there is an equivalent to this type in C. In the question specified, I got an answer I want to convert to C: double trans = trackBar1.Value / 5000.0; double trans = trackBar1.Value / 5000d; Of course, the only change is the second line gone, but with the thing about the decimal type, I

Is there a C equivalent of C#'s decimal type?

时间秒杀一切 提交于 2020-11-29 04:35:12
问题 In relation to: Convert Decimal to Double Now, I got to many questions relating to C#'s floating-point type called decimal and I've seen its differences with both float and double , which got me thinking if there is an equivalent to this type in C. In the question specified, I got an answer I want to convert to C: double trans = trackBar1.Value / 5000.0; double trans = trackBar1.Value / 5000d; Of course, the only change is the second line gone, but with the thing about the decimal type, I

Why does 0.1 + 0.2 return unpredictable float results in JavaScript while 0.2 + 0.3 does not?

匆匆过客 提交于 2020-11-28 02:09:35
问题 0.1 + 0.2 // => 0.30000000000000004 0.2 + 0.2 // => 0.4 0.3 + 0.2 // => 0.5 I understand it has to do with floating points but what exactly is happening here? As per @Eric Postpischil's comment, this isn't a duplicate: That one only involves why “noise” appears in one addition. This one asks why “noise” appears in one addition and does not appear in another. That is not answered in the other question. Therefore, this is not a duplicate. In fact, the reason for the difference is not due to

Why does 0.1 + 0.2 return unpredictable float results in JavaScript while 0.2 + 0.3 does not?

依然范特西╮ 提交于 2020-11-28 02:04:59
问题 0.1 + 0.2 // => 0.30000000000000004 0.2 + 0.2 // => 0.4 0.3 + 0.2 // => 0.5 I understand it has to do with floating points but what exactly is happening here? As per @Eric Postpischil's comment, this isn't a duplicate: That one only involves why “noise” appears in one addition. This one asks why “noise” appears in one addition and does not appear in another. That is not answered in the other question. Therefore, this is not a duplicate. In fact, the reason for the difference is not due to