www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - BigRational class posted

reply hellcatv hotmail.com writes:
I took Arcane Jill's Int class and made a BigRational wrapper around it.
Now I'm sure that not everyone wants to use Rationals with BigIntegers so I made
the BigRational struct be a template taking in an argument. (it's a struct
because potentially the wrapped class is a native type without need for dynamic
alloc)

currently I've done some aliases with the version command

dmd --version=Long *.d
will alias BigRational(Long,1) rational;// the 1 means simplify fractions at
each stage
otherwise the alias is 
alias BigRational(Int,0) rational;//big integer, don't simply fraction

it's been tested with both long and rational, albiet not heavily...
I'm on a hasty time schedule but like to release early and often :-)

http://svn.dsource.org/svn/projects/deliria/turing/

you can find BigRational.d there, vec.d (which is a vector of 2,3,4 rationals,
floats ints or reals...not doubles because of the linker bug with dmd.exe)

and a small test in main.d that shows you how to use them

if you find this useful drop me a line :-)
May 30 2004
parent reply Arcane Jill <Arcane_member pathlink.com> writes:
In article <c9c6qd$24pj$1 digitaldaemon.com>, hellcatv hotmail.com says...
I took Arcane Jill's Int class and made a BigRational wrapper around it.
Now I'm sure that not everyone wants to use Rationals with BigIntegers so I made
the BigRational struct be a template taking in an argument. (it's a struct
because potentially the wrapped class is a native type without need for dynamic
alloc)
Hey, cool. That was fast. Just a few observations (from your post, not from your code, which I haven't lookad at yet). I think that the filename should be all lowercase, because of the style guide, and because of the difference in file case handling between Windows and Linux. It would be nice to just call it Rational. The "Big" prefix is not really necessary, and it would be nice for us to kinda use the same naming style. Well, I think so anyway, but who am I to start telling people what to call their own classes? ;-) I'd be happy for this to coexist in the etc package. I don't see anyone else objecting either. But I am impressed at rapidly you got this together. This is excellent! I should mention that there was a bug in my toString() and toHexString() functions, which is now fixed, so you might care to redownload and rebuild. Arcane Jill
May 30 2004
parent reply hellcatv hotmail.com writes:
aye...the internal class is aliased to rational.
oh I forgot to mention it's BSD license... (that should be compatible for
everyone)

how about this: 
I can't get any of this modules stuff to work properly--when I compiled your
bigints the compiler went haywire about two modules with the exception module
and two modules with the bigint module...
would you care to (at your leisure) integrate the BigRational into your etc
codebase?  I don't think my random project is necessarily the right "permanent
home" for BigRational...  (or we can figure out how to give both of us access to
your codebase and I coudl integrate it in-but then it probably wouldn't be as
stylewise consistent)

feel free to change function names to be more consistent.

I also think that vec.d deserves consideration as part of the etc library...
because so many people are writing their own vec classes... and this one has
everything Cg has to offer.
I just updated the files with the BSD license

-Daniel
In article <c9cccj$2c1d$1 digitaldaemon.com>, Arcane Jill says...
In article <c9c6qd$24pj$1 digitaldaemon.com>, hellcatv hotmail.com says...
I took Arcane Jill's Int class and made a BigRational wrapper around it.
Now I'm sure that not everyone wants to use Rationals with BigIntegers so I made
the BigRational struct be a template taking in an argument. (it's a struct
because potentially the wrapped class is a native type without need for dynamic
alloc)
Hey, cool. That was fast. Just a few observations (from your post, not from your code, which I haven't lookad at yet). I think that the filename should be all lowercase, because of the style guide, and because of the difference in file case handling between Windows and Linux. It would be nice to just call it Rational. The "Big" prefix is not really necessary, and it would be nice for us to kinda use the same naming style. Well, I think so anyway, but who am I to start telling people what to call their own classes? ;-) I'd be happy for this to coexist in the etc package. I don't see anyone else objecting either. But I am impressed at rapidly you got this together. This is excellent! I should mention that there was a bug in my toString() and toHexString() functions, which is now fixed, so you might care to redownload and rebuild. Arcane Jill
May 30 2004
next sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
hellcatv hotmail.com wrote:

feel free to change function names to be more consistent.

I also think that vec.d deserves consideration as part of the etc library...
because so many people are writing their own vec classes... and this one has
everything Cg has to offer.
I just updated the files with the BSD license

-Daniel
  
Parhaps there should be an etc.math3d module namespace for all the 3d stuff in etc. -- -Anderson: http://badmama.com.au/~anderson/
May 30 2004
prev sibling parent reply Arcane Jill <Arcane_member pathlink.com> writes:
In article <c9d3p6$8tm$1 digitaldaemon.com>, hellcatv hotmail.com says...
aye...the internal class is aliased to rational.
oh I forgot to mention it's BSD license... (that should be compatible for
everyone)

how about this: 
I can't get any of this modules stuff to work properly--when I compiled your
bigints the compiler went haywire about two modules with the exception module
and two modules with the bigint module...
Errmm. I don't understand.
would you care to (at your leisure) integrate the BigRational into your etc
codebase?  I don't think my random project is necessarily the right "permanent
home" for BigRational...  (or we can figure out how to give both of us access to
your codebase and I coudl integrate it in-but then it probably wouldn't be as
stylewise consistent)
Sure thing. No probs. Easiest thing to do is for you to hang onto it for a few days, because I'm trying to get a project set up on dsource. (I sent them an email but haven't had a reply yet). It will be a lot easier to integrate stuff once everything is nicely Subverted (is that the right word?) into an svn respository. Also Ivan Senji has given me instructions on how to build a library, so I'll give that a bash, and hopefully the next release can contain an actual library you can link against, which should solve a lot of building headaches.
I also think that vec.d deserves consideration as part of the etc library...
because so many people are writing their own vec classes... and this one has
everything Cg has to offer.
Cool. But ... I don't own the etc namespace. I used it because Walter said it was the most appropriate place. I'm still not completely sure whether it's a free-for-all or something that Walter needs to ok. I didn't ask anyone to "consider" my class for etc. Actually, originally, it was going to be arcane.bigint. Now I'm rather hoping that it gets consideration for inclusion in "std". I don't really have any objection to anyone putting things into etc, but, like I said, it's not my namespace. It's either Walter's, or it's everybody's. In the absence of a clear policy, either you just go ahead and hope it's ok, or ask Walter. In any case, I'm the wrong person to ask, and I'm not actually involved with Digital Mars.
I just updated the files with the BSD license
Best sort. Mine's a variant of BSD. The dsource project may take a few days to sort out. Especially as it's a weekend now. But hopefully by next weekend it will all be up and running. Arcane Jill
May 30 2004
next sibling parent hellcatv hotmail.com writes:
I found the problem with the modules (and checked in the modified version to my
dsource location 
http://svn.dsource.org/svn/projects/deliria/turing/

basically in file exception.d you had
module jill.bigint_files.exception

the latest dmd.exe was complaining that bigint_files was in both jill and etc
changing it to etc fixed that :-) so ya when I changed it to module
etc.bigint_files.exception it works.


the only thing really nasty about vec.d is that it uses the Zero template (it
should be called Constant template ) to grab zero, and one for the various
template types...
I probably should put that in an independent module, but I'm not sure how to
deal with the circular dependencies (rational needs the constant class, vec
needs the constant class AND the rational class, the constant class needs its
constituant types)
that's why I just slapped this template Zero(T) into the rational class (that
didn't have any 3rd party dependencies... perhaps we can work out a better
solution.


In article <c9d7fu$dvo$1 digitaldaemon.com>, Arcane Jill says...
In article <c9d3p6$8tm$1 digitaldaemon.com>, hellcatv hotmail.com says...
aye...the internal class is aliased to rational.
oh I forgot to mention it's BSD license... (that should be compatible for
everyone)

how about this: 
I can't get any of this modules stuff to work properly--when I compiled your
bigints the compiler went haywire about two modules with the exception module
and two modules with the bigint module...
Errmm. I don't understand.
would you care to (at your leisure) integrate the BigRational into your etc
codebase?  I don't think my random project is necessarily the right "permanent
home" for BigRational...  (or we can figure out how to give both of us access to
your codebase and I coudl integrate it in-but then it probably wouldn't be as
stylewise consistent)
Sure thing. No probs. Easiest thing to do is for you to hang onto it for a few days, because I'm trying to get a project set up on dsource. (I sent them an email but haven't had a reply yet). It will be a lot easier to integrate stuff once everything is nicely Subverted (is that the right word?) into an svn respository. Also Ivan Senji has given me instructions on how to build a library, so I'll give that a bash, and hopefully the next release can contain an actual library you can link against, which should solve a lot of building headaches.
I also think that vec.d deserves consideration as part of the etc library...
because so many people are writing their own vec classes... and this one has
everything Cg has to offer.
Cool. But ... I don't own the etc namespace. I used it because Walter said it was the most appropriate place. I'm still not completely sure whether it's a free-for-all or something that Walter needs to ok. I didn't ask anyone to "consider" my class for etc. Actually, originally, it was going to be arcane.bigint. Now I'm rather hoping that it gets consideration for inclusion in "std". I don't really have any objection to anyone putting things into etc, but, like I said, it's not my namespace. It's either Walter's, or it's everybody's. In the absence of a clear policy, either you just go ahead and hope it's ok, or ask Walter. In any case, I'm the wrong person to ask, and I'm not actually involved with Digital Mars.
I just updated the files with the BSD license
Best sort. Mine's a variant of BSD. The dsource project may take a few days to sort out. Especially as it's a weekend now. But hopefully by next weekend it will all be up and running. Arcane Jill
May 30 2004
prev sibling parent reply Brad Anderson <brad sankaty.dot.com> writes:
Jill,

I haven't seen a request for a project yet, but if you're waiting, all I 
need is a name of the project.  Deimos?

BA



 
 The dsource project may take a few days to sort out. Especially as it's a
 weekend now. But hopefully by next weekend it will all be up and running.
 
 Arcane Jill
 
 
May 30 2004
next sibling parent reply "Carlos Santander B." <carlos8294 msn.com> writes:
"Brad Anderson" <brad sankaty.dot.com> escribió en el mensaje
news:c9dvnu$1de9$1 digitaldaemon.com
| Jill,
|
| I haven't seen a request for a project yet, but if you're waiting, all I
| need is a name of the project.  Deimos?
|
| BA
|
|
|

I've meaning to say this for a couple of weeks now, but I was hoping someone
else could point it out. Sometime ago Daniel Yokomiso (who seems to also
have disappeared from here) wrote a library named Deimos Template Library. I
don't even know if it compiles anymore, and I don't think it went beyond the
first release, but I just thought it should be noted. You can check for it
here http://www.minddrome.com/produtos/d/.

-----------------------
Carlos Santander Bernal
May 30 2004
parent reply J C Calvarese <jcc7 cox.net> writes:
Carlos Santander B. wrote:
 "Brad Anderson" <brad sankaty.dot.com> escribió en el mensaje
 news:c9dvnu$1de9$1 digitaldaemon.com
 | Jill,
 |
 | I haven't seen a request for a project yet, but if you're waiting, all I
 | need is a name of the project.  Deimos?
 |
 | BA
 
 I've meaning to say this for a couple of weeks now, but I was hoping someone
 else could point it out. Sometime ago Daniel Yokomiso (who seems to also
 have disappeared from here) wrote a library named Deimos Template Library. I
 don't even know if it compiles anymore, and I don't think it went beyond the
 first release, but I just thought it should be noted. You can check for it
 here http://www.minddrome.com/produtos/d/.
 
 -----------------------
 Carlos Santander Bernal
I forgot this project was called Deimos Template Library. My memory abbreviated it to DTL. I think a cool name like Deimos should be used by an active library rather than by one that's been gathering dust. Deimos Template Library doesn't compile anymore. I think it's been abandoned by its author. The release was apparently on 25 Nov 2002 (http://www.digitalmars.com/drn-bin/wwwnews?D/9596). Some changes have occurred since the release of Deimos Template Library 0.0.1: - deprecation of instance and C-style casts (DMD 0.88) - renaming of apply to opApply (DMD 0.75) - change of syntax of WYSIWYG strings (DMD 0.69) Unfortunately, it's quite possible that Daniel Yokomiso has lost interest in D. The last post of his that I found was posted on 11 Oct 2003 (http://www.digitalmars.com/drn-bin/wwwnews?D/18239). -- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
May 30 2004
parent reply Arcane Jill <Arcane_member pathlink.com> writes:
Lest there is any doubt on this point, let me make it clear that I am *not*
claiming ownership, either of the name "Deimos", or the package name "etc". I'm
just using them. In fact, originally, I wasn't going to use either of those
names, thinking they were Digital Mars things - but then Walter said it was the
right thing to do. If it's right for me, it must be right for others, too.

As I see it, it's a place where all of us can put things. So far as I know, the
only entry condition is adherence to the the design philosophy of Phobos (naming
conventions, unittests, design-by-contract, etc.).

No, on second thoughts, there should be a second entry condition. Everything in
Deimos must be open source and free software. (Well, I think so anyway).

So ... if you're designing something, and you're thinking to yourself "this
really should be in Phobos" - then put it in Deimos. Probably /some/ management
of the namespace is in order. (I wouldn't like to see Deimos filling up with
silly functions to count the number of occurences of the letter M in the names
of European politicians, for example). Somehow we're going to have to
self-manage it.

So there should be no problem with this new Deimos co-existing with the Deimos
Template Library, or anything else for that matter.


In article <c9ekjq$2b0n$1 digitaldaemon.com>, J C Calvarese says...
Carlos Santander B. wrote:
 "Brad Anderson" <brad sankaty.dot.com> escribió en el mensaje
 news:c9dvnu$1de9$1 digitaldaemon.com
 | Jill,
 |
 | I haven't seen a request for a project yet, but if you're waiting, all I
 | need is a name of the project.  Deimos?
 |
 | BA
 
 I've meaning to say this for a couple of weeks now, but I was hoping someone
 else could point it out. Sometime ago Daniel Yokomiso (who seems to also
 have disappeared from here) wrote a library named Deimos Template Library. I
 don't even know if it compiles anymore, and I don't think it went beyond the
 first release, but I just thought it should be noted. You can check for it
 here http://www.minddrome.com/produtos/d/.
 
 -----------------------
 Carlos Santander Bernal
I forgot this project was called Deimos Template Library. My memory abbreviated it to DTL. I think a cool name like Deimos should be used by an active library rather than by one that's been gathering dust.
May 31 2004
parent reply "KTC" <me here.com> writes:
"Arcane Jill" wrote...
 No, on second thoughts, there should be a second entry condition.
Everything in
 Deimos must be open source and free software. (Well, I think so anyway).
While I agree with the free software philosophy & believe, this second entry condition as by the definition of "free" software would mean people won't be able to create close source application using it. This of course, depending on your believe could be what you want but for the adoption of the language probably wouldn't work :-D KTC -- Experience is a good school but the fees are high. - Heinrich Heine
May 31 2004
next sibling parent reply Mike Swieton <mike swieton.net> writes:
On Mon, 31 May 2004 13:57:58 +0100, KTC wrote:

 
 "Arcane Jill" wrote...
 No, on second thoughts, there should be a second entry condition.
Everything in
 Deimos must be open source and free software. (Well, I think so anyway).
While I agree with the free software philosophy & believe, this second entry condition as by the definition of "free" software would mean people won't be able to create close source application using it. This of course, depending on your believe could be what you want but for the adoption of the language probably wouldn't work :-D KTC
The ability to create closed-source apps from Free software depends entirely on the license. The FSF's definition of Free is met by many licenses that don't allow that (GPL, for example), but you can also use licenses that will allow closed source development (Such as the BSD license, or public domain). I think it's important that the contrib library be free. It would be a bad thing for one of two main language libraries (Phobos and Deimos) to contain non-Free code. Mike Swieton __ Brutes find out where their talents lie; a bear will not attempt to fly. - Jonathan Swift
May 31 2004
parent reply "KTC" <me here.com> writes:
"Mike Swieton" wrote...
 The ability to create closed-source apps from Free software depends
entirely
 on the license. The FSF's definition of Free is met by many licenses that
 don't allow that (GPL, for example), but you can also use licenses that
will
 allow closed source development (Such as the BSD license, or public
domain).
 I think it's important that the contrib library be free. It would be a bad
 thing for one of two main language libraries (Phobos and Deimos) to
contain
 non-Free code.
Oh sure, I know about all the open source license like BSD that will allow close source development, but those are open source license and not free (as define by FSF) software license. ( I've recently been to a talk by Richard Stallman... ;) ) "The freedom to improve the program, and release your improvements to the public, so that the whole community benefits (freedom 3). Access to the source code is a precondition for this." Back to the issue of license for the library. Of course a open source license is a must, just not necessary a copyleft license... -- Experience is a good school but the fees are high. - Heinrich Heine
Jun 01 2004
parent reply Arcane Jill <Arcane_member pathlink.com> writes:
In article <c9hkhe$i55$1 digitaldaemon.com>, KTC says...
Oh sure, I know about all the open source license like BSD that will allow
close source development, but those are open source license and not free (as
define by FSF) software license. ( I've recently been to a talk by Richard
Stallman... ;) )
      "The freedom to improve the program, and release your improvements to
the public,
       so that the whole community benefits (freedom 3). Access to the
source code is a precondition for this."
Forgive me, I don't see the problem. I based my license on BSD. Apart from the humorous (in my opinion) insertion of the phrase "Intellectual Property Me Arse" (my statment!), it's BSD, pure and simple. Does this not give people "The freedom to improve the program, and release [their] improvements to the public, so that the whole community benefits"? I rather assumed that it DID give that them freedom.
Back to the issue of license for the library. Of course a open source
license is a must, just not necessary a copyleft license...
I've never been that good understanding licences. Please could you explain the difference? (I don't know what "copyleft" means either). Thanks Jill
Jun 01 2004
parent reply "KTC" <me here.com> writes:
"Arcane Jill" wrote...
 Forgive me, I don't see the problem. I based my license on BSD. Apart from
the
 humorous (in my opinion) insertion of the phrase "Intellectual Property Me
Arse"
 (my statment!), it's BSD, pure and simple.

 Does this not give people "The freedom to improve the program, and release
 [their] improvements to the public, so that the whole community benefits"?
I
 rather assumed that it DID give that them freedom.

 I've never been that good understanding licences. Please could you explain
the
 difference? (I don't know what "copyleft" means either).
Okay, I'm probably not the best person at trying to explain things but I'll try anyway... Both BSD & GPL is open source license in the sense that if you're releasing your software under either one of these license, you will be releasing your source code that people can access as well. However, the two license stand at opposite end of the scale. The main difference is what the license allow the people that use your code to do. The free software / GPL / copyleft / FSF end is that if you ever redistrubate things base on the orginal code, then you MUST also make the source code availble as well. I.E. no one can add proprietary extension. (no one that use your code can restrict others (freedom) rights to see the code) The MIT / BSD end is pretty much like placing your code in the public domain. Once someone gotten the code you orginial wrote, they can do what they want with it. They can sell it, add proprietary extension, whatever. The only difference to having it in public domain is that they have to retain your name saying you wrote the code (if they redistribute the codes) or just say you have copyright over some of the code that they're not letting other people see (because they closed the source). So: BSD: open source but people can later close the source (clue x-windows). GPL: once open source, it will for ever stay that way. "The BSD approach works best in some scenarios -- such as for reference implementations of standards aimed at maximum deployment. For instance, having a BSD-licensed implementation will likely boost its widespread adoption far better than a GPL-licensed implementation could, because developers can freely embed such code in existing (proprietary) software." So for the case here, one probably want to use something like a BSD license unless of course you are fully in the camp of Stallman & FSF which believe in no use or development of proprietary software whatsoever (which of course has its merits but that's going way OT....) KTC p.s Yes I know I'm talking about the merits of free software but at the same time posting this in OE6. Don't go into that, that's a completely different story..... -- Experience is a good school but the fees are high. - Heinrich Heine
Jun 01 2004
parent Ben Hinkle <bhinkle4 juno.com> writes:
 So:
     BSD: open source but people can later close the source (clue
     x-windows). GPL: once open source, it will for ever stay that way.
 
 "The BSD approach works best in some scenarios -- such as for reference
 implementations of standards aimed at maximum deployment. For instance,
 having a BSD-licensed implementation will likely boost its widespread
 adoption far better than a GPL-licensed implementation could, because
 developers can freely embed such code in existing (proprietary) software."
 
 So for the case here, one probably want to use something like a BSD
 license unless of course you are fully in the camp of Stallman & FSF which
 believe in no use or development of proprietary software whatsoever (which
 of course has its merits but that's going way OT....)
you are leaving out the very important LGPL "Lesser GPL" or "Library GPL" which allows for linking with closed source software but protects the source code.
Jun 01 2004
prev sibling parent hellcatv hotmail.com writes:
what we have there now is BSD license...
BSD license basically says "you can do whatever with this stuff, just keep my
name somewhere"   i.e. MS could take my BigRational class...package it in MS
word, change it so it delivered the wrong numbers, and use it to calculate
probabilities for the Paperclip to randomly snarf your document, and then blame
it on me ;-) keeping my name on the now-busted BigRational class ;-)

In article <c9fa4d$9cp$1 digitaldaemon.com>, KTC says...
"Arcane Jill" wrote...
 No, on second thoughts, there should be a second entry condition.
Everything in
 Deimos must be open source and free software. (Well, I think so anyway).
While I agree with the free software philosophy & believe, this second entry condition as by the definition of "free" software would mean people won't be able to create close source application using it. This of course, depending on your believe could be what you want but for the adoption of the language probably wouldn't work :-D KTC -- Experience is a good school but the fees are high. - Heinrich Heine
May 31 2004
prev sibling parent reply Arcane Jill <Arcane_member pathlink.com> writes:
In article <c9dvnu$1de9$1 digitaldaemon.com>, Brad Anderson says...
Jill,

I haven't seen a request for a project yet, but if you're waiting, all I 
need is a name of the project.  Deimos?
Deimos, yes. Definitely. You didn't get my email then? Ah well.
May 31 2004
parent reply Brad Anderson <brad dsource.dot.org> writes:
I attempted to send you a mail as well, and it came back.

In any case, Deimos is set up at dsource.org.  If you would register in 
the Forums section, I will use that username to give you WRITE access to 
your Subversion repository.

You can email me at the above address, remove the .dot part

BA



Arcane Jill wrote:
 In article <c9dvnu$1de9$1 digitaldaemon.com>, Brad Anderson says...
 
Jill,

I haven't seen a request for a project yet, but if you're waiting, all I 
need is a name of the project.  Deimos?
Deimos, yes. Definitely. You didn't get my email then? Ah well.
May 31 2004
parent Arcane Jill <Arcane_member pathlink.com> writes:
In article <c9h3uf$2q69$2 digitaldaemon.com>, Brad Anderson says...
I attempted to send you a mail as well, and it came back.
Damn! Well, I suppose my email address must be working to some extent, judging by the amount of spam it receives!
In any case, Deimos is set up at dsource.org.  If you would register in 
the Forums section, I will use that username to give you WRITE access to 
your Subversion repository.
Sounds good. I have done that now (using a different email address).
You can email me at the above address, remove the .dot part
Will do in future. If this discussion needs to continue, we can do it off-list, but it looks like everything should be sorted now anyway. Thanks Arcane Jill
May 31 2004