std.rational?

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Tue Oct 1 02:07:49 PDT 2013


On 28/09/13 13:15, Joseph Rushton Wakeling wrote:
> Well, obviously.  Actually I'm not unhappy with David's name per se but with the
> idea of being inconsistent with how other libraries name these methods.
> Boost.Rational uses the full names, I'll have a look around and see how other
> libraries name them and whether there is consensus.

Boost.Rational, Python's numbers.Rational, Ruby's Rational, Haskell's Ratio, and 
both Common Lisp and Scheme's in-built rational number support all use numerator 
and denominator for their corresponding method names:
http://www.boost.org/doc/libs/1_54_0/libs/rational/rational.html#Numerator%20and%20Denominator
http://docs.python.org/2/library/numbers.html#numbers.Rational
http://docs.python.org/3/library/numbers.html#numbers.Rational
http://www.ruby-doc.org/core-2.0.0/Rational.html
http://www.haskell.org/onlinereport/ratio.html
http://www.lispworks.com/documentation/lw50/CLHS/Body/f_numera.htm
http://www.franz.com/support/documentation/current/ansicl/dictentr/numerato.htm
http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-2.html#node_toc_node_sec_11.7.1

I also came across a Rational.java here which follows the same convention, but I 
don't know how "official" this library is:
http://introcs.cs.princeton.edu/java/32class/Rational.java.html

... while this C# class uses Numerator and Denominator for the public method 
names (hey, it's C#, they have to be different, even if it's only by a capital 
letter:-)
http://exif-utils.googlecode.com/svn/trunk/ExifUtils/ExifUtils/Rational.cs

The one standout I came across was Julia, which uses "num" and "den":
http://docs.julialang.org/en/latest/manual/complex-and-rational-numbers/#rational-numbers

... and also implements an operator // to indicate rational division, which 
looks nice at first glance and then had me thinking, "Oh no, many bugs will come 
from this ..."

In summary, I think we have other-language consensus here, and I'm going to make 
the switch to "numerator", "denominator" as the public method names.  Objections 
can always be brought up at review time :-)


More information about the Digitalmars-d mailing list