Message Boards Message Boards

0
|
3454 Views
|
5 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Difference between SetPrecision and the back tick (`) ?

What is the difference between SetPrecision and `?

0.1`22

outputs 0.1000000000000000000000

but

SetPrecision[0.1,22]

outputs 0.1000000000000000055511.

When you put ` in the Documentation Center, it returns Precision. So what does adding the backtick behind a number do?

5 Replies

Yes, sorry, I realized that in the meantime and edited my last reply.

The code formatting feature can be used by typing Ctrl-K or using the <> button

POSTED BY: Ilian Gachevski

Yes, that's exactly right. The padding still takes place, but it is the binary truncation that results in these extra digits:

In[2]:= FromDigits[RealDigits[0.1, 2], 2]

Out[2]= 3602879701896397/36028797018963968

or 0.1000000000000000055511...

POSTED BY: Ilian Gachevski

You get the same result from

FromDigits[d,2]

as well. So it seems just converting 0.1 to binary causes a difference. How do you get the Input/Output pairs displayed the way you did?

Thanks again.

Thanks for the helpful reply. To make sure I understand, when using SetPrecision, the 0.1 is converted to binary, which must be an approximation since 0.1 is not terminating in binary, and then padded with 0's to achieve the desired base 10 precision. It seems that padding with 0's is not causing the difference but rather the conversion to binary. Is that right?

When an arbitrary precision number is entered with a backtick, the decimal mantissa/significand is used, so what effectively happens is

SetPrecision[1*10^-1, 22]

On the other hand, as documented SetPrecision[0.1, 22] takes the machine precision number 0.1 and pads it with binary zeros. In base 10, the added padding digits will not be zero in general. Try comparing the results of RealDigits in base 2 and base 10 for 0.1, 0.1`22 and SetPrecision[0.1, 22].

POSTED BY: Ilian Gachevski
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract