7.5

Table Of Contents
Calculations and Arithmetic in PlanetPress Talk
Because PlanetPress Talk is a language based on PostScript, there are a few limitations, especially when it comes to cal-
culations, that need to be taken into consideration.
Data Types
There are three types of numerical data types in PlanetPress Talk:
l "Integers" (page 222):Whole numbers that can be positive or negative.
l "Measures" (page 222):Also called "float", numbers with decimals.
l "Currency" (page 223):Currency is a special data type that only has two decimal point precision, used specifically for
displaying dollar amounts on screen.
Rounding
When PlanetPress Talk does rounding, for instance when converting from a Measure to a Currency type using "FloatToCur
(function)" (page 515), rounding is done using the Round half to even method (see: Rounding on Wikipedia). This rounding
method tries to reduce rounding errors by alternating between rounding a .5 value up or down depending on whether the sig-
nificant digit to the left is odd or even.
Though this may give you rounding that seems odd, the method is meant to be used especially with currency calculations,
more specifically addition since it is the most popular action done in PlanetPress. With this method, the more numbers are
added, the less rounding errors are significant.
Calculation precision
While calculations can be done with PlanetPress Talk quickly and efficiently, there is an important consideration to keep in
mind:floating-point values (mesures)are limited to 8 digit decimal places. Any calculation that requires more precision, or any
calculation that can shift non-significant decimal digits within the useable range, should be avoided.
Thus, it is highly recommended to always to your mathematical calculations outside of PlanetPress Design and have the
results available directly, without any further modifications. Objectif Lune, Inc. takes not responsibility for imprecise, or wrong-
ful, calculations in PlanetPress Design.
Tips and Tricks
The following are useful to remember as you write your PlanetPress Talk scripts:
l Defining program logic As for any coding, when you write programs in PlanetPress Talk you should work through
the logic of the program you intend to create before you start coding. This ensures the program accomplishes what you
intend it to accomplish, and makes the coding more straightforward. It can also result in insights into different ways of
accomplishing the same task, or raise issues that were not immediately apparent.
l Test If you are writing a complicated script, it is recommended you use the PlanetPress Talk Editor, and test your code
regularly as you develop it. This helps you discover and solve any problems early on in the development process.
l Simplicity As in any programming language, aim for both simplicity and clarity in your scripts.
l Using mathematical operators Enclose mathematical operators in parentheses ( ) to make your code easier to
read and therefore easier to maintain.
l Performing complex calculations PlanetPress Talk limits its precision to 1/1000 to optimize speed and thus is not
designed to handle complex mathematical computations. If you require greater precision you should perform the cal-
culation outside PlanetPress Talk and include the result in the input data for your document.
l CasePlanetPress Talk is case-insensitive. It is good programming practice to establish case conventions as it enhances
the readability of the resulting code. It is recommended that you use lower case for all PlanetPress Talk reserved
words (names of system variables, operators, and commands) as this is the default case convention of the PlanetPress
©2010 Objectif Lune Inc - 239 -