Questions tagged «fractions»

20
浮点数的range()
range()Python中的浮点数是否等效? >>> range(0.5,5,1.5) [0, 1, 2, 3, 4] >>> range(0.5,5,0.5) Traceback (most recent call last): File "<pyshell#10>", line 1, in <module> range(0.5,5,0.5) ValueError: range() step argument must not be zero

26
表示Java分数的最佳方法?
我正在尝试使用Java中的分数。 我想实现算术函数。为此,我首先需要一种规范功能的方法。我知道我只有一个公分母才能将1/6和1/2加起来。我将不得不添加1/6和3/6。天真的方法会让我加2/12和6/12,然后减少。如何以最少的性能损失获得一个共同的分母?哪种算法最适合呢? 版本8(感谢hstoerr): 改进包括: 现在equals()方法与compareTo()方法一致 final class Fraction extends Number { private int numerator; private int denominator; public Fraction(int numerator, int denominator) { if(denominator == 0) { throw new IllegalArgumentException("denominator is zero"); } if(denominator < 0) { numerator *= -1; denominator *= -1; } this.numerator = numerator; this.denominator = denominator; …
100 java  math  fractions 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.