Forum: Ruby [ANN] fixedpnt 0.0.1: Binary Fixed Point Calculations

8bc3878efaac43db769600d44e5907f3?d=identicon&s=25 Axel Friedrich (axel555)
on 2013-03-20 15:24
https://github.com/Axel2/fixedpnt.rb
Allows simulating binary fixed point calculations done in hardware.

There is another library from Phil Tomson which serves the same purpose
but with different properties:
http://rubyforge.org/projects/fixedpt/

For _decimal_ fixed point calculations there is at least the library
from Karl Brodowsky:
http://rubyforge.org/projects/long-decimal/


Kind Regards,
Axel
5a837592409354297424994e8d62f722?d=identicon&s=25 Ryan Davis (Guest)
on 2013-03-20 22:09
(Received via mailing list)
On Mar 20, 2013, at 07:25 , Axel Friedrich <lists@ruby-forum.com> wrote:

> https://github.com/Axel2/fixedpnt.rb
> Allows simulating binary fixed point calculations done in hardware.

This looks like a good start, but I'd like to suggest some changes:

1) package it as a gem. I'd be happy to help with this.

2) add real tests. If I help with the above, you'll get templates for
this.

3) think about changing the license to ruby, mit, or bsd. gpl is
generally discouraged in our community.
0e6ac58dab6125c1cd2e7ac645076b6f?d=identicon&s=25 Joel VanderWerf (Guest)
on 2013-03-20 22:55
(Received via mailing list)
On 03/20/2013 07:25 AM, Axel Friedrich wrote:
> https://github.com/Axel2/fixedpnt.rb
> Allows simulating binary fixed point calculations done in hardware.

A random api suggestion... consider using #[]= as an alias for #assign,
following this example:

 >> class A; def []=(v); @x = v; end; def []; @x; end; end
=> nil
 >> a = A.new
=> #<A:0x007fdf9c617438>
 >> a[] = 3
=> 3
 >> a[]
=> 3
 >> a
=> #<A:0x007fdf9c617438 @x=3>

You can think of [] as a "dereference operator" for boxed values.

As a bonus, ruby gives these operators some basic assignment semantics:

 >> y = a[] = 4
=> 4
 >> y
=> 4

This works regardless of the actual return value of #[]=.

And:

 >> b = A.new
=> #<A:0x007fdf9c6dee70>
 >> b[] ||= 42
=> 42
 >> b[]
=> 42

The line

   b[] ||= 42

is roughly the same as

   b[] = b[] || 42

and causes a call to #[] followed by #[]=.
18813f71506ebad74179bf8c5a136696?d=identicon&s=25 Eric Wong (Guest)
on 2013-03-20 22:56
(Received via mailing list)
Ryan Davis <ryand-ruby@zenspider.com> wrote:
> 3) think about changing the license to ruby, mit, or bsd. gpl is
> generally discouraged in our community.

I encourage Axel to choose the license he feels is best.

I've never felt discouraged for releasing LGPL/GPL/AGPL code,
but I'd never betray my personal beliefs for popularity, either.
8bc3878efaac43db769600d44e5907f3?d=identicon&s=25 Axel Friedrich (axel555)
on 2013-03-21 11:41
Thank you for your suggestions!

> 1) package it as a gem. I'd be happy to help with this.

I'm happy to accept your help. I never built a gem before.


> 2) add real tests. If I help with the above, you'll get templates for
> this.

I'll try to do so.


> 3) think about changing the license to ruby, mit, or bsd. gpl is
> generally discouraged in our community.

The truth is, I didn't want to bother with license. But I felt, I need
one, and GPL was one I often saw together with software. That's the only
reason why I took GPL. - Saying, "license is same as Ruby's", would that
be enough? Or, can the most important advantages/disadvantages of
ruby/mit/bsd be told in a few easy sentences? I need not to have it
perfect.

Axel
8bc3878efaac43db769600d44e5907f3?d=identicon&s=25 Axel Friedrich (axel555)
on 2013-03-21 11:51
> A random api suggestion... consider using #[]= as an alias for #assign,

I see the advantages. Only thing is, I can't remember to have seen this
before, without any "argument" inside []. I mean, for example,
'hello'[0] = 'H', has a 0 as "argument" inside []. Isn't this syntax
(without argument) very strange or would it be seen as "good ruby"/"the
ruby way"?

Axel
99804651e19d8b0dffbc0da53e39114e?d=identicon&s=25 Adam Prescott (Guest)
on 2013-03-21 12:44
(Received via mailing list)
On 21 March 2013 10:41, Axel Friedrich <lists@ruby-forum.com> wrote:
> The truth is, I didn't want to bother with license. But I felt, I need
> one, and GPL was one I often saw together with software. That's the only
> reason why I took GPL. - Saying, "license is same as Ruby's", would that
> be enough? Or, can the most important advantages/disadvantages of
> ruby/mit/bsd be told in a few easy sentences? I need not to have it
> perfect.

One of the concerns people have with the GPL is that it is copyleft,
meaning you cannot add "restrictions" later on: any rights granted to
the software through the GPL cannot be removed in any derivatives. It
is in some sense "viral". If you use GPL'd derived code in your work,
it cannot be proprietary and closed, it must be as free as the GPL.

In contrast, the more "permissive" licenses like MIT/BSD/ISC place
very few restrictions beyond attribution (through maintaining the
copyright notice), so that, say, MIT-licensed code can be included in
proprietary software, or the license on the code itself changed
(sublicensing). (For this reason, MIT is shorter and doesn't require a
lot of legalese.) It turns the "keep it free" aspect into a social,
contribute-back-to-the-community issue.

You should pick whichever license covers your intent of the code. Do
you want it to be free "permanently" (GPL or another copyleft
license), or do you want to be more permissive (MIT/BSD/ISC or
similar)?

As a mini aside, you can also look at the Apache license, which
includes other clauses like assuming contributions are also under the
Apache license. Note this is different from copyleft, like the GPL.
I'd actually really like to see a license that is MIT-style + this
clause. I actually did a write-up[1] of this kinda stuff, if you're
curious, where I also looked at taking contributions and including
those in the copyright notice. Some projects have a lot of
contributions but this never gets fed back into the copyright notice,
which is a bit of a shame if there are significant contributors.

[1]: https://aprescott.com/posts/open-source-copyright
C24646fadce91fe3b868a99b386f386e?d=identicon&s=25 Grant Olson (Guest)
on 2013-03-21 12:56
(Received via mailing list)
On 03/21/2013 06:41 AM, Axel Friedrich wrote:
>> 3) think about changing the license to ruby, mit, or bsd. gpl is
>> generally discouraged in our community.
>
> The truth is, I didn't want to bother with license. But I felt, I need
> one, and GPL was one I often saw together with software. That's the only
> reason why I took GPL. - Saying, "license is same as Ruby's", would that
> be enough? Or, can the most important advantages/disadvantages of
> ruby/mit/bsd be told in a few easy sentences? I need not to have it
> perfect.
>

The MIT and BSD licenses basically ensure that you get attribution for
your work.  If someone wants to redistribute the software themselves,
they must include your license.

The GPL does that too, but it also requires that developers who use the
library in their own work make available the source code, and make
available any changes they've made to the source code.

If you just want a license that ensures (1) other developers can legally
use your code for themselves and (2) you receive credit, then an MIT or
BSD license is fine.

If you're concerned that a big faceless corporation is going to make
changes to your code that it doesn't release to the public, then you
want the GPL.

--
- Grant

https://www.rubygems-openpgp-ca.org/ Sign your gems.
0e6ac58dab6125c1cd2e7ac645076b6f?d=identicon&s=25 Joel VanderWerf (Guest)
on 2013-03-21 17:56
(Received via mailing list)
On 03/21/2013 03:51 AM, Axel Friedrich wrote:
>> A random api suggestion... consider using #[]= as an alias for #assign,
>
> I see the advantages. Only thing is, I can't remember to have seen this
> before, without any "argument" inside []. I mean, for example,
> 'hello'[0] = 'H', has a 0 as "argument" inside []. Isn't this syntax
> (without argument) very strange or would it be seen as "good ruby"/"the
> ruby way"?

A reasonable concern. I don't think I've seen this construct (#[]= and
#[] with no args) used before either. Every other operator forces a
particular arity. I see no reason not to take advantage of this special
case. The ruby way is in the eye of the beholder...
8bc3878efaac43db769600d44e5907f3?d=identicon&s=25 Axel Friedrich (axel555)
on 2013-03-21 18:18
>>> A random api suggestion... consider using #[]= as an alias for #assign,

>> ...
> ...I see no reason not to take advantage of this special
> case. The ruby way is in the eye of the beholder...

I'll implement it as alias. So me (and others?) can try out which feels
more handy.

Axel
5a837592409354297424994e8d62f722?d=identicon&s=25 Ryan Davis (Guest)
on 2013-03-22 22:25
(Received via mailing list)
On Mar 21, 2013, at 03:41 , Axel Friedrich <lists@ruby-forum.com> wrote:

> I'll try to do so.
Done. I sent you a pull request a minute ago.
8bc3878efaac43db769600d44e5907f3?d=identicon&s=25 Axel Friedrich (axel555)
on 2013-03-26 14:45
> https://github.com/Axel2/fixedpnt.rb
> Allows simulating binary fixed point calculations done in hardware.

* It's available as gem now: fixedpnt.
* License changed to MIT.
* Some small changes.


Kind Regards,
Axel
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.