分数问题 [英] Fraction Problems

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

问题描述

大家好,我正在开发一个数学程序,其中我需要程序来解释,例如1/3像0.3333 ...而不是逗号之后的有限数量的数字。我认为可以通过说它没有确切的方式来完成。结果和存储分数的两个整数以获得更好的准确性,但我想知道你是否有更好的想法,或者你可以帮助这样做。我有另一个问题:如果我将1除以3​​,计算机使用多少个数来进行除法? (=逗号后面有多少个数字)

解决方案


大家好,我正在开发一个数学课程,其中我需要程序解释,例如,1/3像0.3333 ...而不是逗号后的有限数量的数字。我认为可以通过说它没有确切的方式来完成。结果和存储分数的两个整数以获得更好的准确性,但我想知道你是否有更好的想法,或者你可以帮助这样做。我有另一个问题:如果我将1除以3​​,计算机使用多少个数来进行除法? (=逗号后面有多少个数字)



更好的准确性是一个相对的术语。 .333333333333和.3333333333333有什么区别?几乎没有,你做的任何计算对12位数都很重要。如果要提高准确度,请使用更大的数据类型,或者可以编写基于小数值估算分数的程序。基于小数估计分数的方法是采用类似.3333333333的值并将其转换为3333333333/10000000000然后减少分数。


在回答您的其他问题时,计算机用于进行除法的数量取决于您的系统设置的数量。大多数浮点数是32位,但它们可以更大或更小。



更好的准确性是一个相对的术语。 .333333333333和.3333333333333有什么区别?几乎没有,你做的任何计算对12位数都很重要。如果要提高准确度,请使用更大的数据类型,或者可以编写基于小数值估算分数的程序。基于小数估计分数的方法是采用类似.3333333333的值并将其转换为3333333333/10000000000然后减少分数。


在回答您的其他问题时,计算机用于进行除法的数量取决于您的系统设置的数量。大多数浮点数是32位,但它们可以更大或更小。



问题是我需要电脑来比较数字,例如,如果它是0.999999999999999999999999它会说它不等于1


这取决于您的应用程序需要的准确程度。如果您正在寻找无限精度,那么有可用的库。在这个库中应该有比较和其他有用操作的方法。


如果你正在寻找只能精确到20位左右的东西,那么当你进行比较时就这样做你测试最后一位数字。


Hi guys, I am currently developing a math program in which i need the program to interpret, for instance, 1/3 like 0.3333... instead of a limited number of numbers after the comma. I thought it could be done by saying it has no "exact" result and storing the two integers of the fraction to get a better accuracy, but i wanted to know whether you had a better idea or maybe you could help doing this. I have another question: if i divide 1 by 3, how many numbers does the computer use to make the division?? (=how many numbers after the comma)

解决方案

Hi guys, I am currently developing a math program in which i need the program to interpret, for instance, 1/3 like 0.3333... instead of a limited number of numbers after the comma. I thought it could be done by saying it has no "exact" result and storing the two integers of the fraction to get a better accuracy, but i wanted to know whether you had a better idea or maybe you could help doing this. I have another question: if i divide 1 by 3, how many numbers does the computer use to make the division?? (=how many numbers after the comma)

"better accuracy" is a relative term. What is the difference between .333333333333 and .3333333333333? Virtually nothing, and any calculation you do will be significant to 12 digits. If you want to increase accuracy use a larger data type or you can write a program that estimates a fraction based on a decimal value. The way to estimate a fraction based on a decimal is you take a value like .3333333333 and turn it into 3333333333 / 10000000000 then reduce the fraction.

In answer to your other question the amount of numbers the computer uses to make the division depends on what your system is set up to be. Most floats are 32 bits, but they can be larger or smaller.


"better accuracy" is a relative term. What is the difference between .333333333333 and .3333333333333? Virtually nothing, and any calculation you do will be significant to 12 digits. If you want to increase accuracy use a larger data type or you can write a program that estimates a fraction based on a decimal value. The way to estimate a fraction based on a decimal is you take a value like .3333333333 and turn it into 3333333333 / 10000000000 then reduce the fraction.

In answer to your other question the amount of numbers the computer uses to make the division depends on what your system is set up to be. Most floats are 32 bits, but they can be larger or smaller.


The thing is that i need the computer to compare numbers and, for instance, if it is 0.999999999999999999999999 it will say it''s not equal to 1


It depends on how accurate your application needs to be. If you are looking for infinite precision then there are libraries available for this. In this library there should be methods for compare and other useful operations.

If you are looking for something that is only accurate to 20 digits or so then make it so when you do a compare you test the very last digit.


这篇关于分数问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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