continued-fractions

Continued Fractions Python [closed]

倾然丶 夕夏残阳落幕 提交于 2021-02-08 15:01:58
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . Improve this question I am new to Python and was asked to create a program that would take an input as a non-negative integer n and then compute an approximation for the value of e using the first n + 1 terms of the continued fraction: I have attempted to decipher the question but

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

Continued logarithm arithmetic: floor operator on run-length encoded terms

℡╲_俬逩灬. 提交于 2019-12-11 01:28:11
问题 I'm trying to implement basic arithmetic on Bill Gosper's continued logarithms, which are a 'mutation' of continued fractions allowing the term co-routines to emit and consume very small messages even on very large or very small numbers. Reversible arithmetic, such as {+,-,*,/} are fairly straightforwardly described by Gosper at least in a unary representation, but I'm having difficulty implementing the modulo operator which effectively truncates information from the division operation. I've

Algorithm Challenge: Generate Continued Fractions for a float

六眼飞鱼酱① 提交于 2019-11-30 05:11:59
( EDIT : In response to grumpy comments, No it isn't homework. I am working on pitch detection, taking an array of potential harmonic peaks, and attempting to construct candidates for fundamental frequency. So, it is actually a very practical question.) Consider the best fractional approximations for (eg) pi, ordered by increasing denominator: 3/1, 22/7, 355/113, ... Challenge: create a tidy C algorithm that will generate the n'th quotient approximation a/b for a given float, returning also the discrepancy. calcBestFrac(float frac, int n, int * a, int * b, float * err) {...} The best technique

Algorithm Challenge: Generate Continued Fractions for a float

断了今生、忘了曾经 提交于 2019-11-29 03:06:05
问题 ( EDIT : In response to grumpy comments, No it isn't homework. I am working on pitch detection, taking an array of potential harmonic peaks, and attempting to construct candidates for fundamental frequency. So, it is actually a very practical question.) Consider the best fractional approximations for (eg) pi, ordered by increasing denominator: 3/1, 22/7, 355/113, ... Challenge: create a tidy C algorithm that will generate the n'th quotient approximation a/b for a given float, returning also