Quantcast

uint64 typecast can't be initialised with more than 15 decimal positions

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

uint64 typecast can't be initialised with more than 15 decimal positions

Yury T.
In theory, uint64 could be initialised with numbers up to (4G)^2-1 (20 decimal positions).

In reality, only 15 decimal positions can be input correctly -- demonstrated by the following snip (checked on 3.6.2 version):

a = uint64( 999999999999999 ) * 10000
b = uint64( 9999999999999999 )
a = a + 1
b = b+1

I feel the fix would be elementary, but the possible implications make me stop and think -- is there a possibility to check the correctness of integer arithmetics in 64 bits?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: uint64 typecast can't be initialised with more than 15 decimal positions

Jordi Gutiérrez Hermoso-2
On 4 March 2013 09:29, Yury T. <[hidden email]> wrote:
> In theory, uint64 could be initialised with numbers up to (4G)^2-1 (20
> decimal positions).
>
> In reality, only 15 decimal positions can be input correctly -- demonstrated
> by the following snip (checked on 3.6.2 version):

    http://wiki.octave.org/FAQ#How_do_I_make_Octave_use_more_precision.3F

HTH,
- Jordi G. H.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: uint64 typecast can't be initialised with more than 15 decimal positions

Yury T.
Thank you very much, indeed.

However, I must comment on the document quoted (and yes, I can and will edit it, just as 'anybody' can -- later).

First thing, such limitations aren't meant to be found in FAQ, but in manual (which I tried beforehand). Plot window disappearing too fast -- FAQ materiel; uint64 initialisation -- not FAQ materiel.

The quoted FAQ section contains info on integers, floating point precision and symbolic computation, all bunched up together. This is wrong.

Also, talking about integers presupposes talking about limits, not precision -- how big are the integer numbers you can use with the help of data types: uint32, uint64 etc.

If uint64() works by converting its input somehow through the IEEE floats (16 positions after the decimal point), than it is doing it wrong, anyway. 1) In my snip, `b` should be assigned the correct value (0.9{repeated 16 times}E+1). 2) The rounding of the input shouldn't go unnoticed, and ideally should throw a rounding exception or rounding error (we talk integers which have absolute precision by definition).

I've corrected the part on integer limit in FAQ, but the rest of the comments stands.

Is the FAQ really a place for the ads?



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: uint64 typecast can't be initialised with more than 15 decimal positions

Jordi Gutiérrez Hermoso-2
On 4 March 2013 11:23, Yury T. <[hidden email]> wrote:
> First thing, such limitations aren't meant to be found in FAQ, but in manual
> (which I tried beforehand). Plot window disappearing too fast -- FAQ
> materiel; uint64 initialisation -- not FAQ materiel.

Sure, moving material from the FAQ to the manual is fine, with the FAQ
pointing to the manual is good. Do you have a suggestion on how to
reword the manual?

> The quoted FAQ section contains info on integers, floating point precision
> and symbolic computation, all bunched up together. This is wrong.

No, it's all about more precision, which is indeed a FAQ.

> Also, talking about integers presupposes talking about *limits, not
> precision* -- how big are the integer numbers you can use with the help of
> data types: uint32, uint64 etc.

That is precision:

    http://en.wikipedia.org/wiki/Precision_%28computer_science%29

> If uint64() works by converting its input somehow through the IEEE floats
> (16 positions after the decimal point), than it is doing it wrong, anyway.

I suppose the FAQ entry isn't clear. The problem isn't uint64, but
that the Octave and Matlab languages don't have integer literals. Any
numerical literal is first read by the interpreter as a double. With
JITC, sometimes you can optimise this and guess the type, but this is
just a transparent optimisation. The semantics of the language do not
allow integer literals.

> Is the FAQ really a place for the ads?

Sure, why not? If you dislike it, remove it. It's a wiki.

- Jordi G. H.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: uint64 typecast can't be initialised with more than 15 decimal positions

Yury T.
Jordi Gutiérrez Hermoso-2 wrote
Sure, moving material from the FAQ to the manual is fine, with the FAQ
pointing to the manual is good. Do you have a suggestion on how to
reword the manual?
Yes, but I can't jump in rewriting right now. Generally, on the lines of what I'm talking about here. BTW, I have already partly rewritten several manual fragments on complex datatypes (as mentioned in the previous discussion). Only it's in Russian (but translates adequately with Google), and not finished (I remade only the parts of immediate concern to me). I can post it as a work-in-progress somewhere.

Jordi Gutiérrez Hermoso-2 wrote
> Also, talking about integers presupposes talking about *limits, not
> precision* -- how big are the integer numbers you can use with the help of
> data types: uint32, uint64 etc.

That is precision:

    http://en.wikipedia.org/wiki/Precision_%28computer_science%29
Most definitely it is NOT. Even as wiki-entry says, precision is an amount of detail, and you can't be any more detailed with machine-represented integer, as you already are. One is one. But there are magnitude limits.

Jordi Gutiérrez Hermoso-2 wrote
> If uint64() works by converting its input somehow through the IEEE floats
> (16 positions after the decimal point), than it is doing it wrong, anyway.

I suppose the FAQ entry isn't clear. The problem isn't uint64, but
that the Octave and Matlab languages don't have integer literals. Any
numerical literal is first read by the interpreter as a double. With
JITC, sometimes you can optimise this and guess the type, but this is
just a transparent optimisation. The semantics of the language do not
allow integer literals.
If the function silently rounds the integer (!!), then the function's, well, functioning is wrong, wrong and, once again, wrong. The only rational decision would be to limit the interpreter input by number of decimal places (and throw an error) or, better yet, to throw a rounding error in such cases. Definitely not silently round the supposedly integer input.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: uint64 typecast can't be initialised with more than 15 decimal positions

Jordi Gutiérrez Hermoso-2
On 4 March 2013 12:03, Yury T. <[hidden email]> wrote:
> Jordi Gutiérrez Hermoso-2 wrote
>> Sure, moving material from the FAQ to the manual is fine, with the FAQ
>> pointing to the manual is good. Do you have a suggestion on how to
>> reword the manual?
>
> Yes, but I can't jump in rewriting right now. Generally, on the
> lines of what I'm talking about here.

I'm busy and lazy. ;-)

It's easier if you just write it and make it easy for me to
incorporate your changes.

>  BTW, I have already partly rewritten several manual fragments on
> complex datatypes (as mentioned in the previous discussion). Only
> it's in Russian (but translates adequately with Google), and not
> finished (I remade only the parts of immediate concern to me). I can
> post it as a work-in-progress somewhere.

Sure. Also post the original Russian. Я тоже говорю немножко по-русски.

> Jordi Gutiérrez Hermoso-2 wrote
>>> Also, talking about integers presupposes talking about *limits, not
>>> precision* -- how big are the integer numbers you can use with the help
>>> of
>>> data types: uint32, uint64 etc.
>>
>> That is precision:
>>
>>     http://en.wikipedia.org/wiki/Precision_%28computer_science%29
>
> Most definitely it is NOT. Even as wiki-entry says, precision is an amount
> of detail, and you can't be any more detailed with machine-represented
> integer, as you already are. One is one. But there are magnitude limits.

An uint64 has 64 bits of precision, which is the point here. There are
simply more bits with which to represent quantities, even if these
quantities have to be integral. This is more precision than the 52
bits of a double's mantissa. An uint64 thus has more precision than a
double. A double can represent numbers as large as an uint64, but with
less precision. The limits are the same, the precision is not.

But again, if you strongly disagree, go ahead and rewrite the FAQ.

> Jordi Gutiérrez Hermoso-2 wrote

>>> If uint64() works by converting its input somehow through the IEEE
>>> floats (16 positions after the decimal point), than it is doing it
>>> wrong, anyway.
>>
>> I suppose the FAQ entry isn't clear. The problem isn't uint64, but
>> that the Octave and Matlab languages don't have integer literals.
>> Any numerical literal is first read by the interpreter as a double.
>> With JITC, sometimes you can optimise this and guess the type, but
>> this is just a transparent optimisation. The semantics of the
>> language do not allow integer literals.
>
> If the function silently rounds the integer (!!), then the
> function's, well, functioning is wrong, wrong and, once again,
> wrong.

The function is doing no such thing. The function is being fed a
double that has already been rounded by the interpreter, before the
function ever sees it.

> The only rational decision would be to limit the interpreter input
> by number of decimal places (and throw an error)

This would break compatibility with Matlab, since this works there
without error. We could warn, if you want, "numeric literal cannot be
represented with double precision".

> or, better yet, to throw a rounding error in such cases. Definitely
> not silently round the supposedly integer input.

Rounding is the best that can be done, especially if we are to keep
Matlab compatibility. If this bothers you so much, I will welcome a
patch to make the interpreter warn in this case.

- Jordi G. H.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: uint64 typecast can't be initialised with more than 15 decimal positions

Jordi Gutiérrez Hermoso-2
On 4 March 2013 12:26, Jordi Gutiérrez Hermoso <[hidden email]> wrote:
> An uint64 has 64 bits of precision, which is the point here.

I should have added, In C++, numeric_limits<T>::digits gives you the
precision of each data type. This is different from
numeric_limits<T>::max() which gives you the maximum value it can
represent:

    http://ideone.com/3RSELF

- Jordi G. H.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: uint64 typecast can't be initialised with more than 15 decimal positions

Yury T.
In reply to this post by Jordi Gutiérrez Hermoso-2
Jordi Gutiérrez Hermoso-2 wrote
It's easier if you just write it and make it easy for me to
incorporate your changes.
...
Sure. Also post the original Russian. Я тоже говорю немножко по-русски.
Okay, let's try working that way. And as for my draft on datatypes, it's in OpenOffice, so it WILL be posted in Russian (that is, "as is") :).

Jordi Gutiérrez Hermoso-2 wrote
> Most definitely it is NOT. Even as wiki-entry says, precision is an amount
> of detail, and you can't be any more detailed with machine-represented
> integer, as you already are. One is one. But there are magnitude limits.

An uint64 has 64 bits of precision, which is the point here. There are
simply more bits with which to represent quantities, even if these
quantities have to be integral. This is more precision than the 52
bits of a double's mantissa. An uint64 thus has more precision than a
double. A double can represent numbers as large as an uint64, but with
less precision. The limits are the same, the precision is not.

But again, if you strongly disagree, go ahead and rewrite the FAQ.
IEEE's double may represent (in 64 bits) roughly +-0.9{times 16}x10+-308. This limit is way over any integer limit using comparable binary resources. Representation loses precision for ANY number requiring more than 16 significant figures in mantiss.

Now, integer datatype may represent (in 64 bits) roughly +-8x10^18, but this representation is, however, always precise.

This is fundamental difference, whatever the docs saying otherwise say.

I will just go ahead, then.

Jordi Gutiérrez Hermoso-2 wrote
>>> If uint64() works by converting its input somehow through the IEEE
> If the function silently rounds the integer (!!), then the
The function is doing no such thing. The function is being fed a
double that has already been rounded by the interpreter, before the
function ever sees it.

> The only rational decision would be to limit the interpreter input
> by number of decimal places (and throw an error)

This would break compatibility with Matlab, since this works there
without error. We could warn, if you want, "numeric literal cannot be
represented with double precision".
Ah, the Matlab compatibility... Please-please, add at least either this signalling or any other kind of warning. The current situation is unacceptable. E.g., I would be in a goodly pickle if I didn't check what actually goes in into uint64.

And I wouldn't try to coax this modification out of competent folks, if I were competent to do it myself (like previously, with utf8 in plot windows).
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: uint64 typecast can't be initialised with more than 15 decimal positions

Jordi Gutiérrez Hermoso-2
On 4 March 2013 12:59, Yury T. <[hidden email]> wrote:
> Now, integer datatype may represent (in 64 bits) roughly +-8x10^18,
> but this representation is, however, *always precise*.

It's precise as long as you don't do computations that exceed this
precision. When your computations exceed this precision, you'll get
wrong results that if I recall correctly, as undefined behaviour
according to the C++ standard (perhaps they're implementation defined
instead of undefined, can't remember).

> Ah, the Matlab compatibility... Please-please, add at least either
> this signalling or any other kind of warning. The current situation
> is unacceptable.

Most people don't notice, I don't think it's a problem, and I don't
really care. If you care so much, and you can't provide a patch
yourself consider paying someone to do this for you.

- Jordi G. H.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: uint64 typecast can't be initialised with more than 15 decimal positions

Jordi Gutiérrez Hermoso-2
On 4 March 2013 13:10, Jordi Gutiérrez Hermoso <[hidden email]> wrote:
> When your computations exceed this precision, you'll get wrong
> results that if I recall correctly, as undefined behaviour according
> to the C++ standard (perhaps they're implementation defined instead
> of undefined, can't remember).

And in the Matlab and hence Octave languages, if you exceed the
integral precision during a computation you get the fantastically
bizarre saturation semantics that are actually really tricky to
implement in C++. Did you know that these saturation semantics are why
Octave had 64-bit integer arithmetic implemented before Matlab? Octave
won a pointless race with Matlab here that nobody knows about and
nobody cares about.

- Jordi G. H.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: uint64 typecast can't be initialised with more than 15 decimal positions

Yury T.
In reply to this post by Jordi Gutiérrez Hermoso-2
Jordi Gutiérrez Hermoso-2 wrote
Most people don't notice, I don't think it's a problem, and I don't
really care. If you care so much, and you can't provide a patch
yourself consider paying someone to do this for you.
Do you personally own or direct this franchise, then?

My request was meant for all competent folks reading the list.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: uint64 typecast can't be initialised with more than 15 decimal positions

Jordi Gutiérrez Hermoso-2
On 4 March 2013 13:21, Yury T. <[hidden email]> wrote:
> Jordi Gutiérrez Hermoso-2 wrote
>> Most people don't notice, I don't think it's a problem, and I don't
>> really care. If you care so much, and you can't provide a patch
>> yourself consider paying someone to do this for you.
>
> Do you personally own or direct this franchise, then?

No, of course not.

> My request was meant for all competent folks reading the list.

Sure, if you can find someone else who wants to do this work without
pay, go ahead, I'll apply the patch.

- Jordi G. H.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: uint64 typecast can't be initialised with more than 15 decimal positions

Yury T.
In reply to this post by Jordi Gutiérrez Hermoso-2
I would understand more of this, if you were using a standard, textbook terminology, not a techno-speak, popular as it may be.

Limit is set on quantity (maximum or minimum), precision shows how much detail is achieved/retained (and can't be "exceeded"), saturation is a situation of no (more) gain for more input. In programming, there are situations of quantity potentially (or actually) exceeding the upper limit (int or float), or falling below the precision threshold (float) etc.

I've got from this that you were somehow involved in the pointless race you mention and expended resources for no gain, but frankly I don't feel I should show more concern for this more than you do for my small problem.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: uint64 typecast can't be initialised with more than 15 decimal positions

Jordi Gutiérrez Hermoso-2
On 4 March 2013 14:24, Yury T. <[hidden email]> wrote:
> I've got from this that you were somehow involved in the pointless race you
> mention and expended resources for no gain, but frankly I don't feel I
> should show more concern for this more than you do for my small problem.

Indeed, there is no obligation to do so on either side. Both of us
have more important problems to work on, no doubt.

- Jordi G. H.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Loading...