Is double precision for floating point calculation the default?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Is double precision for floating point calculation the default?

ttonon
Greetings,
In a program, I need all my calculations, which are floating point decimal,
to be double precision (accurate to 10E-16).  Is that the default, or must I
make an explicit command for that precision, and if so, what is the command?
Thanks.

Tom



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Is double precision for floating point calculation the default?

José Abílio Matos

On Saturday, 21 March 2020 03.59.34 WET ttonon wrote:

> Greetings,

> In a program, I need all my calculations, which are floating point decimal,

> to be double precision (accurate to 10E-16). Is that the default, or must I

> make an explicit command for that precision, and if so, what is the

> command? Thanks.

>

> Tom

 

Yes it is the default:

 

As an example:

 

>> class(5)

ans = double

>> eps(1)

ans = 2.2204e-16

 

--

José Matos



Reply | Threaded
Open this post in threaded view
|

Re: Is double precision for floating point calculation the default?

ttonon
José Abílio Matos wrote

> On Saturday, 21 March 2020 03.59.34 WET ttonon wrote:
>> Greetings,
>> In a program, I need all my calculations, which are floating point
>> decimal,
>> to be double precision (accurate to 10E-16).  Is that the default, or
>> must I
>> make an explicit command for that precision, and if so, what is the
>> command? Thanks.
>>
>> Tom
>
> Yes it is the default:
>
> As an example:
>
>>> class(5)
> ans = double
>>> eps(1)
> ans = 2.2204e-16
>
> --
> José Matos

Thanks.  It may be confusing because the answers contain only four
significant places after the decimal point.  Is there a command to force the
answer to display all 16 figures, as in

>> pi
ans =  3.1415926535897932?  

Also a figure like 2.2204e-16 is accurate only to 2.e-16.  Correct?  (Just
want to be sure.)
Tom






--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Is double precision for floating point calculation the default?

José Abílio Matos

On Saturday, 21 March 2020 12.33.24 WET ttonon wrote:

> >> pi

>

> ans = 3.1415926535897932?

 

See the help for format.

 

>> pi

ans = 3.1416

>> format long

>> pi

ans = 3.141592653589793

 

> Also a figure like 2.2204e-16 is accurate only to 2.e-16. Correct? (Just

> want to be sure.)

 

Nope.

The value that you mention is the separation between the value represented and the next value represented by floating point representation.

 

>> eps

ans = 2.220446049250313e-16

 

All those digits are significant. Simplifying we can say basically that we have ~16 digits for each floating point number (that is a simplified but mostly accurate picture).

 

> Tom

 

 

--

José Matos



Reply | Threaded
Open this post in threaded view
|

Re: Is double precision for floating point calculation the default?

Benson Muite
In reply to this post by ttonon
On Sat, Mar 21, 2020, at 3:33 PM, ttonon wrote:

> José Abílio Matos wrote
> > On Saturday, 21 March 2020 03.59.34 WET ttonon wrote:
> >> Greetings,
> >> In a program, I need all my calculations, which are floating point
> >> decimal,
> >> to be double precision (accurate to 10E-16).  Is that the default, or
> >> must I
> >> make an explicit command for that precision, and if so, what is the
> >> command? Thanks.
> >>
> >> Tom
> >
> > Yes it is the default:
> >
> > As an example:
> >
> >>> class(5)
> > ans = double
> >>> eps(1)
> > ans = 2.2204e-16
> >
> > --
> > José Matos
>
> Thanks.  It may be confusing because the answers contain only four
> significant places after the decimal point.  Is there a command to force the
> answer to display all 16 figures, as in
>
> >> pi
> ans =  3.1415926535897932?  
>
> Also a figure like 2.2204e-16 is accurate only to 2.e-16.  Correct?  (Just
> want to be sure.)
> Tom
>
>
>
>
>
>
> --
> Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
>
To display all 16 digits use type
>>format long
>>pi
Not quite, floating point number are represented by a mantissa and an exponent. Mantissa can have 16 digits in double precision. Some information on floating point is at:
https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
https://ryanstutorials.net/binary-tutorial/binary-floating-point.php
https://en.wikipedia.org/wiki/Floating-point_arithmetic
https://en.wikipedia.org/wiki/IEEE_754
>


Reply | Threaded
Open this post in threaded view
|

Re: Is double precision for floating point calculation the default?

ttonon
Benson and Jose, yes of course.  I had a lapse of cognition there.  Thanks.
Tom



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html