rational-numbers

Rational numbers in C# and XML

I'm working with an XML file that subscribes to an industry standard. The standards document for the schema defines one of the fields as a rational number and its data is represented as two integers, typically with the second value being a 1 (e.g. <foo>20 1</foo>). I've been hunting around without a great deal of success to see if there'...

Pure Python rational numbers module for 2.5

Has anybody seen such a thing? Small self-sufficient modules are preferred. ...

How to convert rational and decimal number strings to floats in python?

How can I convert strings which can denote decimal or rational numbers to floats >>> ["0.1234", "1/2"] ['0.1234', '1/2'] I'd want [0.1234, 0.5]. eval is what I was thinking but no luck: >>> eval("1/2") 0 ...

Rational number calculator

I want to make a rational number calculator, but I don't know how to neglect some characters. E.g., if the program has to calculate the expression "2/9+9/3" and the answer should be in unsimplified form, how to neglect '/' in the above expression while taking input? ...

Algorithm for detecting repeating decimals?

Is there an algorithm for figuring out the following things? If the result of a division is a repeating decimal (in binary). If it repeats, at what digit (represented as a power of 2) does the repetition start? What digits repeat? Some examples: 1/2 = 1/10 = 0.1 // 1 = false, 2 = N/A, 3 = N/A, 4 = N/A 1/3 = 1/11 = 0.010101... // 1 =...

How best to represent rational numbers in SQL Server?

I'm working with data that is natively supplied as rational numbers. I have a slick generic C# class which beautifully represents this data in C# and allows conversion to many other forms. Unfortunately, when I turn around and want to store this in SQL, I've got a couple solutions in mind but none of them are very satisfying. Here is an...