View mode: basic / threaded / horizontal-split · Log in · Help
June 07, 2012
Rational numbers in D
Sorry for the double-post -- I already asked this in d-learn, but this may be a 
better place to ask.

What's the current state of affairs and roadmap for inclusion of rational number 
support in D?  I've come across David Simcha's work:
http://cis.jhu.edu/~dsimcha/d/phobos/std_rational.html

... and a feature request on the bugzilla:
http://d.puremagic.com/issues/show_bug.cgi?id=7885

... but this isn't mentioned at all in the review queue:
http://prowiki.org/wiki4d/wiki.cgi?ReviewQueue

What's the status of work/planning for this feature and is there any kind of ETA 
for when it might land in Phobos?

Thanks and best wishes,

    -- Joe
June 08, 2012
Re: Rational numbers in D
On Thursday, 7 June 2012 at 17:49:22 UTC, Joseph Rushton Wakeling 
wrote:
> Sorry for the double-post -- I already asked this in d-learn, 
> but this may be a better place to ask.
>
> What's the current state of affairs and roadmap for inclusion 
> of rational number support in D?  I've come across David 
> Simcha's work:
> http://cis.jhu.edu/~dsimcha/d/phobos/std_rational.html
>
> ... and a feature request on the bugzilla:
> http://d.puremagic.com/issues/show_bug.cgi?id=7885
>
> ... but this isn't mentioned at all in the review queue:
> http://prowiki.org/wiki4d/wiki.cgi?ReviewQueue
>
> What's the status of work/planning for this feature and is 
> there any kind of ETA for when it might land in Phobos?
>
> Thanks and best wishes,
>
>     -- Joe

I don't think anyone intends to ignore your posts, it's just that 
we don't have the answer. Jonathan Davis has a new thread 
regarding the review queue. You might get answers there.

I think there is a tendency for discussions in this group to 
focus on language internals and features rather than useful but 
mundane things. As a last resort you could probably check and/or 
complete the rational number code and put it in the review queue 
yourself. Most code here is licensed to allow that.

Taking a little longer view, we definitely need a better process 
for inclusion of new modules into phobos. Maybe, as you suggest, 
a roadmap for proposed modules, with dates for implementation and 
reviews.

Paul
June 08, 2012
Re: Rational numbers in D
On 08/06/12 18:06, Paul D. Anderson wrote:
> I don't think anyone intends to ignore your posts, it's just that we don't have
> the answer. Jonathan Davis has a new thread regarding the review queue. You
> might get answers there.

It wasn't really that I was feeling ignored (OK, put this as a tribute to the 
speed at which questions are usually answered:-), more that I thought the 
discussion might be more useful/suited here as it's about a module under 
development.  Again, sorry for the double post.

> I think there is a tendency for discussions in this group to focus on language
> internals and features rather than useful but mundane things. As a last resort
> you could probably check and/or complete the rational number code and put it in
> the review queue yourself. Most code here is licensed to allow that.

I'll take a look and see what I can do.

> Taking a little longer view, we definitely need a better process for inclusion
> of new modules into phobos. Maybe, as you suggest, a roadmap for proposed
> modules, with dates for implementation and reviews.

I guess it's tricky because there are only a limited number of people who can 
review the code, so it must be difficult to set definite time targets.  But it 
could be nice to have e.g. a priority wish list so that we can see what kinds of 
contributions would be most useful/welcome.
June 09, 2012
Re: Rational numbers in D
On 07/06/2012 18:49, Joseph Rushton Wakeling wrote:
> Sorry for the double-post -- I already asked this in d-learn, but this may be a better
> place to ask.
>
> What's the current state of affairs and roadmap for inclusion of rational number support
> in D?

Including it in D seems very unlikely.

Including it in Phobos, OTOH, is another matter.

> I've come across David Simcha's work:
> http://cis.jhu.edu/~dsimcha/d/phobos/std_rational.html
>
> ... and a feature request on the bugzilla:
> http://d.puremagic.com/issues/show_bug.cgi?id=7885
<snip>

Well, do these work at the moment?

If so, I suggest you use one of them for now.  If you're mainly just doing simple 
arithmetic with them, it probably wouldn't be too much work to convert your code to use 
the Phobos rational type when/if it gets one.

Stewart.
June 09, 2012
Re: Rational numbers in D
On Saturday, 9 June 2012 at 01:11:49 UTC, Stewart Gordon wrote:
> On 07/06/2012 18:49, Joseph Rushton Wakeling wrote:
>> Sorry for the double-post -- I already asked this in d-learn, 
>> but this may be a better
>> place to ask.
>>
>> What's the current state of affairs and roadmap for inclusion 
>> of rational number support
>> in D?
>
> Including it in D seems very unlikely.
>
> Including it in Phobos, OTOH, is another matter.
>
>> I've come across David Simcha's work:
>> http://cis.jhu.edu/~dsimcha/d/phobos/std_rational.html
>>
>> ... and a feature request on the bugzilla:
>> http://d.puremagic.com/issues/show_bug.cgi?id=7885
> <snip>
>
> Well, do these work at the moment?
>
> If so, I suggest you use one of them for now.  If you're mainly 
> just doing simple arithmetic with them, it probably wouldn't be 
> too much work to convert your code to use the Phobos rational 
> type when/if it gets one.
>
> Stewart.

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.
June 09, 2012
Re: Rational numbers in D
SomeDude:

> 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.

I have had to use Rational nunbers in D two or three times (once 
during simplification of expressions that contain operations 
among integer numbers, to not lose exact precision with floating 
point numbers). I have written a rationals module for D1 and 
later I have converted it to D2. So you see two persons that have 
implemented them.

It's a small module, that uses std.bigint, it's not a binding to 
C code, so putting it in Deimos is not necessary. I'd like a 
rationals module in Phobos.

Bye,
bearophile
June 09, 2012
Re: Rational numbers in D
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?
June 09, 2012
Re: Rational numbers in D
On 09.06.2012 21: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?

Prescaling works just fine. That is use plain integer and assume it 
holds value in the smallest fraction possible. Then define functions 
that do scale and round it to tone, note etc.

-- 
Dmitry Olshansky
June 09, 2012
Re: Rational numbers in D
On 09/06/12 16:08, bearophile wrote:
> I have had to use Rational nunbers in D two or three times (once during
> simplification of expressions that contain operations among integer numbers, to
> not lose exact precision with floating point numbers). I have written a
> rationals module for D1 and later I have converted it to D2. So you see two
> persons that have implemented them.
>
> It's a small module, that uses std.bigint, it's not a binding to C code, so
> putting it in Deimos is not necessary. I'd like a rationals module in Phobos.

... so, I can lend my voice to support inclusion of your module :-)  Is there 
anything more practical that I could do to assist?
June 09, 2012
Re: Rational numbers in D
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.
« First   ‹ Prev
1 2 3
Top | Discussion index | About this forum | D home