Rational numbers in D

Stewart Gordon smjg_1998 at yahoo.com
Sat Jun 9 16:52:33 PDT 2012


On 09/06/2012 18:47, Joseph Rushton Wakeling wrote:
> On Saturday, 9 June 2012 at 01:11:49 UTC, Stewart Gordon wrote:
>> Including it in D seems very unlikely.
>>
>> Including it in Phobos, OTOH, is another matter.
>
> My bad phrasing.  Of course in Phobos.
>
>
> On 09/06/12 08:25, SomeDude wrote:
>> I've never had any use for rational numbers as have 99% of developers I believe.
>> Maybe I'm overlooking something, but I see only two possible usages of them:
>> math packages and length quotations in the english system. Because of this, I'd
>> rather see them in Deimos than in Phobos.
>
> In fact the application I had in mind was for music software, where you want to be able to
> store pitch changes in fractions of a whole tone.  In that context it's important that
> adding up those changes be guaranteed to produce exact results.
>
> e.g. if you take middle C and raise it by 1 whole tone _exactly_ you arrive at the note
> D.  If you raise it by 0.99999999999999999999999999995 instead, how does your software
> reliably handle this?

By using an integer type to store pitches in such a way that the semitone is the basic unit.

Do you compose music that makes use of demisemitones, thirds of tones, and so on?

Stewart.


More information about the Digitalmars-d mailing list