The Mathematica Journal
Departments
Download This Issue
Home
Feature Articles
Graphics Gallery
Tricks of the Trade
In and Out
Columns
The Mathematica Programmer
New Products
New Publications
Classifieds
Calendar
News Bulletins
Editor's Pick
Mailbox
Letters
Write Us
About the Journal
Staff and Contributors
Submissions
Subscriptions
Advertising
Back Issues

Setting Precision in Binary Digits

Q: I would like to specify the precision of my numbers in binary digits rather than decimal digits. Is there any way of doing this?
A: Rob Knapp (rknapp@wolfram.com) answers: The precision of numbers in Mathematica is kept as a real quantity. This means that you can easily specify a precision in binary digits by multiplying it by [Graphics:../Images/index_gr_107.gif]. For example, here we specify [Graphics:../Images/index_gr_108.gif] to 20 binary digits.
[Graphics:../Images/index_gr_109.gif]
[Graphics:../Images/index_gr_110.gif]
[Graphics:../Images/index_gr_111.gif]
[Graphics:../Images/index_gr_112.gif]
Using FullForm gives you the fractional (with respect to base 10) precision.
[Graphics:../Images/index_gr_113.gif]
[Graphics:../Images/index_gr_114.gif]
By default, Precision rounds to the nearest integer.
[Graphics:../Images/index_gr_115.gif]
[Graphics:../Images/index_gr_116.gif]

In Mathematica 4 there is an option to prevent this rounding.

[Graphics:../Images/index_gr_117.gif]
[Graphics:../Images/index_gr_118.gif]
[Graphics:../Images/index_gr_119.gif]
[Graphics:../Images/index_gr_120.gif]
If we examine the RealDigits of n in base 2,
[Graphics:../Images/index_gr_121.gif]
[Graphics:../Images/index_gr_122.gif]
we see that there are 20 binary digits.
[Graphics:../Images/index_gr_123.gif]
[Graphics:../Images/index_gr_124.gif]
Another way to display the same information is using BaseForm.
[Graphics:../Images/index_gr_125.gif]
[Graphics:../Images/index_gr_126.gif]
You can enter a number in an arbitrary base using base^^digits see Sections 3.1.3 and A.2.5 of The Mathematica Book).
[Graphics:../Images/index_gr_127.gif]
[Graphics:../Images/index_gr_128.gif]
The result is identical to that obtained using SetPrecision.
[Graphics:../Images/index_gr_129.gif]
[Graphics:../Images/index_gr_130.gif]


Converted by Mathematica      September 29, 1999 [Prev Page][Next Page]