NATURALs

8 messages Options
Embed this post
Permalink
Raphael Mack-2

NATURALs

Reply Threaded More More options
Print post
Permalink
Hi,

Thank you ver much Cyril, for the fixes in the XML Parser. It looks very
good in my use case now.

Now (not related to your changes) I have some problems with the
NATURAL_* classes:

- I'm somehow missing a to_real_32 and to_real_64 feature in NATURAL_*
classes.



- How can I convert an INTEGER_8 into a NATURAL_8? I just want to "cast"
them, i.e. the binary representation shall stay the same and I want to
use the complete range of NATURALs.

Do we need features force_to_integer_* (same as to_integer but without
checking fit_natural_X)?

In other words: How do I assign 0xff into a NATURAL_8?

0xff.to_natural_8 gives a precondition violation at runtime, but the
tutorial tells us to use NATURALs this way...



- a feature to_hexadecimal as in integer_* would be nice in natural_*



- How to shift naturals? Is there a reason why "|>>" is not implemented
there? I patched the compiler locally and it seems to work.


Thanks for reading this mail until here. I'm looking forward to get an
answer. - I'm also happy, if someone not part of the se core team read
this, thinks about it and tells me his/her thoughts.

If there is any way I can help to implement the features I mention here
and we agree, that they are missing, please tell me. I do not have time
to maintain SmartEiffel, but I'm willing to help out with some simple
tasks on the was to get the next release done.


I wish you all a happy new year, and that you find time to work on the
projects you like (not only (Smart)Eiffel related)!

Cheers,
Rapha

Raphael Mack-2

Re: NATURALs

Reply Threaded More More options
Print post
Permalink
Hi,

another question:

Is there a reason why naturals do not provide features to convert
between them? i. e. NATURAL_8.to_natural_16?

It seems, that adding them in the NATURAL_X.e files is enough to support
the correct behaviour. Am I missing something?

Rapha

Dominique Colnet

Re: NATURALs

Reply Threaded More More options
Print post
Permalink
In reply to this post by Raphael Mack-2
On Thu, 2009-01-01 at 14:22 +0100, Raphael Mack wrote:
> Now (not related to your changes) I have some problems with the
> NATURAL_* classes:
>
> - I'm somehow missing a to_real_32 and to_real_64 feature in NATURAL_*
> classes.
You are right. Just added.

> - How can I convert an INTEGER_8 into a NATURAL_8? I just want to "cast"
> them, i.e. the binary representation shall stay the same and I want to
> use the complete range of NATURALs.
I have also added some more conversion methods.
As usual, all to_natural_* functions cannot loose information
(i.e. the printed value is the same before ans after conversion).

As usual, the force_to_natural_* function family is a simple cast.

> Do we need features force_to_integer_* (same as to_integer but without
> checking fit_natural_X)?
>
> In other words: How do I assign 0xff into a NATURAL_8?
 natural_8 := (0xFF).to_natural_8
 -- not tested, but should be equivalent to:
 natural_8 := 255.to_natural_8

> 0xff.to_natural_8 gives a precondition violation at runtime, but the
> tutorial tells us to use NATURALs this way...
Hummm, I will check that. Thanks.
--
--------------------------------------------------------------
[hidden email] -- IUT Nancy Charlemagne -- LORIA
http://SmartEiffel.loria.fr  --  The GNU Eiffel Compiler
POST: Loria, B.P. 239,54506 Vandoeuvre les Nancy Cedex, FRANCE
Voice:+33 0354503827 Mobile: +33 0665362381 Fax:+33 0383913201

Raphael Mack-2

Re: NATURALs

Reply Threaded More More options
Print post
Permalink
Hi,

Am Dienstag, den 13.01.2009, 18:40 +0100 schrieb Dominique Colnet:
> On Thu, 2009-01-01 at 14:22 +0100, Raphael Mack wrote:
> > - I'm somehow missing a to_real_32 and to_real_64 feature in NATURAL_*
> > classes.
> You are right. Just added.
[...]

cool, Thank you very much.

> > - How can I convert an INTEGER_8 into a NATURAL_8? I just want to "cast"
> > them, i.e. the binary representation shall stay the same and I want to
> > use the complete range of NATURALs.
> I have also added some more conversion methods.
> As usual, all to_natural_* functions cannot loose information
> (i.e. the printed value is the same before ans after conversion).
>
> As usual, the force_to_natural_* function family is a simple cast.

I guess so. But the intention of my question was to understand, whether
force_to_natural_* in NATURAL_* classes are not there intentionally. I
guess these have to be added. Or am I just to blind to see them right
now? Also the force_to_integer_X in NATURAL_X.


I had two questions about shifting and to_hexadecimal, do you consider
these? I have implemented them locally, if you want I can prepare a
patch. If you want I'd also implement a test for these.

Thanks again, I really appreciate your work.

Rapha

Dominique Colnet

Re: NATURALs

Reply Threaded More More options
Print post
Permalink
In reply to this post by Dominique Colnet
On Tue, 2009-01-13 at 18:40 +0100, Dominique Colnet wrote:
> > In other words: How do I assign 0xff into a NATURAL_8?
You cannot (see below).
>  natural_8 := (0xFF).to_natural_8
>  -- not tested, but should be equivalent to:
>  natural_8 := 255.to_natural_8
Ooops, sorry. Forget my previous comment. Il will try to be correct and
clear now:
 0xFF
has only one type, and is of type INTEGER_8 and thus is actually value
-1 mapped on 8 bits.
Where 255 is of type INTEGER_16 which can be be legally stored into
a NATURAL_8.
> > 0xff.to_natural_8 gives a precondition violation at runtime, but the
> > tutorial tells us to use NATURALs this way...
Well, any negative value will broke the require.
> Hummm, I will check that. Thanks.
Hope this is clear now. BTW, the principle that one expression
has only one static type regardless the context was a good
choice I think.
Cheers,
--
--------------------------------------------------------------
[hidden email] -- IUT Nancy Charlemagne -- LORIA
http://SmartEiffel.loria.fr  --  The GNU Eiffel Compiler
POST: Loria, B.P. 239,54506 Vandoeuvre les Nancy Cedex, FRANCE
Voice:+33 0354503827 Mobile: +33 0665362381 Fax:+33 0383913201

Dominique Colnet

Re: NATURALs

Reply Threaded More More options
Print post
Permalink
In reply to this post by Raphael Mack-2
On Tue, 2009-01-13 at 19:16 +0100, Raphael Mack wrote:
> > As usual, the force_to_natural_* function family is a simple cast.
>
> I guess so. But the intention of my question was to understand, whether
> force_to_natural_* in NATURAL_* classes are not there intentionally. I
> guess these have to be added. Or am I just to blind to see them right
> now? Also the force_to_integer_X in NATURAL_X.
I think that the library (as well as the language) must try to avoid
error prone methods.
As an example natural_64.force_to_natural_32 would be error prone or at
least unclear. Indeed the force_to_natural_32 name does not tell what
part of the natural_64 is written into the smallest area.
When the size in number of bits is the same, there is no problem.
>
> I had two questions about shifting and to_hexadecimal, do you consider
> these? I have implemented them locally, if you want I can prepare a
> patch. If you want I'd also implement a test for these.
About shifting, why not, but we must avoid mistakes we made in INTEGER.
As an example, I prefer to avoid having two names for the same function.
The more I look at cryptic #<< |>>> |<<, the more I prefer ordinary
method names.
Cheers,
--
--------------------------------------------------------------
[hidden email] -- IUT Nancy Charlemagne -- LORIA
http://SmartEiffel.loria.fr  --  The GNU Eiffel Compiler
POST: Loria, B.P. 239,54506 Vandoeuvre les Nancy Cedex, FRANCE
Voice:+33 0354503827 Mobile: +33 0665362381 Fax:+33 0383913201

Raphael Mack-2

Re: NATURALs

Reply Threaded More More options
Print post
Permalink
In reply to this post by Dominique Colnet
Hi,

Am Donnerstag, den 15.01.2009, 18:12 +0100 schrieb Dominique Colnet:
> On Tue, 2009-01-13 at 18:40 +0100, Dominique Colnet wrote:
> > > In other words: How do I assign 0xff into a NATURAL_8?
> You cannot (see below).

;-)

> >  natural_8 := (0xFF).to_natural_8
> >  -- not tested, but should be equivalent to:
> >  natural_8 := 255.to_natural_8
> Ooops, sorry. Forget my previous comment. Il will try to be correct and
> clear now:
>  0xFF
> has only one type, and is of type INTEGER_8 and thus is actually value
> -1 mapped on 8 bits.
> Where 255 is of type INTEGER_16 which can be be legally stored into
> a NATURAL_8.

I understand that, but I doubt its usefulness. I think assigning 0xFF to
an INTEGER_8 should be prohibited. If one thinks in bits or hex number
he always should use NATURALs. If he means an integer 255 should be the
choice. If an INTEGER_8 is meant I'd prefer to write {INTEGER_8 -1}

I'm convinced, that whenever hex number formats come to ones mind one
thinks in NATURALS.

> > > 0xff.to_natural_8 gives a precondition violation at runtime, but the
> > > tutorial tells us to use NATURALs this way...
> Well, any negative value will broke the require.

Yes, of course. But 0xff is not negative (in my eyes.)

> Hope this is clear now. BTW, the principle that one expression
> has only one static type regardless the context was a good
> choice I think.

Yes, I also think that. But still think, that writing integers in
hexadecimal format is very stange (and yes, I work in OS business for
embedded systems, so I am familiar to thinking in bit masks, and hex
numbers - integers I know from school and nobody wrote 0xff there when
he meant -1)

If you think 0xff should have type INTEGER_8, then I think a
force_to_natural_8 shall be provided in INTEGER_8, because writing

n: NATURAL_8
n := 0x88.force_to_natural_8

is far better to understand when you mean the most significant bit in
each nibble to be set then writing:

n := 136.to_natural_8

(Even though I'd prefer:
n := 0x88
as you know)

Cheers,
Rapha

Raphael Mack-2

Re: NATURALs

Reply Threaded More More options
Print post
Permalink
In reply to this post by Dominique Colnet
Am Donnerstag, den 15.01.2009, 19:18 +0100 schrieb Dominique Colnet:

> On Tue, 2009-01-13 at 19:16 +0100, Raphael Mack wrote:
> > > As usual, the force_to_natural_* function family is a simple cast.
> >
> > I guess so. But the intention of my question was to understand, whether
> > force_to_natural_* in NATURAL_* classes are not there intentionally. I
> > guess these have to be added. Or am I just to blind to see them right
> > now? Also the force_to_integer_X in NATURAL_X.
> I think that the library (as well as the language) must try to avoid
> error prone methods.
> As an example natural_64.force_to_natural_32 would be error prone or at
> least unclear. Indeed the force_to_natural_32 name does not tell what
> part of the natural_64 is written into the smallest area.

Good argument! So we have to find better names. - I still think that
cutting away high part's of a NATURAL is an important feature.


> > I had two questions about shifting and to_hexadecimal, do you consider
> > these? I have implemented them locally, if you want I can prepare a
> > patch. If you want I'd also implement a test for these.
> About shifting, why not, but we must avoid mistakes we made in INTEGER.
> As an example, I prefer to avoid having two names for the same function.
> The more I look at cryptic #<< |>>> |<<, the more I prefer ordinary
> method names.

yes, this is fine for me. I always have to look up which of |<< or #<<
is what I want. I could even think of obsoleting the cryptic aliases for
shifting and rotating. These names are much more clear!

Cheers,
Rapha