小数到分数转换算法,它如何工作? [英] Decimals to Fractions Conversion Algorithm, how does it work?

查看:110
本文介绍了小数到分数转换算法,它如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个谐波比率程序,我希望用户能够做的部分工作是插入各种比率,并让正在播放的十进制值频率向您显示更多更高或更高的比率锁定频率.降低.

I'm working on a harmonic ratio program and part of what I want a user to be able to do is plug in various ratios and have the decimal-valued frequency that's playing show you more ratio-locked frequencies that are higher or lower.

无论如何,此网页上有一个JavaScript算法可以显示给定小数的小数值(比率).

Anyway, on this webpage there is a javascript algorithm to show fractional values (ratios) from given decimals.

http://www.mindspring.com/~alanh/fracs.html

它如何工作?我对自己实现它很感兴趣,但是我不太了解它是如何工作的.如果您尝试使用某些分数,它将为您提供许多选择(有些还有额外的小数),因此它不仅仅只是GCD.

How does it work? I am interested in implementing it myself, but I don't really understand how it functions. If you try out some fractions, it gives you many options (some with extra decimals) so it's not exactly just GCD.

如果这个算法问题更适合程序员.请告诉我,我将在此处重新张贴并删除它.

edit: if this algorithm question would be better suited for programmers.se just let me know and I'll repost there and delete this.

推荐答案

它正在计算并显示连续分数.连续分数中的每个术语都会为您提供另一个分数,该分数要好一个数量级.

It is calculating the continued fraction and displaying that. Each term in the continued fraction gives you another fraction that is an order of magnitude better.

请参阅用于将小数简化为分数的算法,以获取更详细的解释以及可以选择使用的替代算法.

See Algorithm for simplifying decimal to fractions for more detailed explanations and alternative algorithms that you could choose to use.

这篇关于小数到分数转换算法,它如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆