

Chapter 3  Mathematical and Logical Utilities
This chapter describes a number of utility routines that you can use to perform mathematical and logical operations supported directly by the Macintosh Operating System. In particular, this chapter discusses how you can
You need to read this chapter only if you need access to any of these features. With the exception of the mathematical operations and conversions, the routines this chapter describes are intended for programmers who occasionally need to access some of these features and do not require that the algorithms used to implement them be sophisticated. For example, if you are developing an advanced mathematical application, the pseudorandom number generator built into the Operating System might be too simplistic to fit your needs. Similarly, if you wish to access individual bits of memory in a timecritical loop, the Operating System routines that perform these operations are probably too slow to be practical.
 perform lowlevel logical manipulation of bits and bytes when using a compiler that does not directly support such manipulations
 save disk space by using simple compression and decompression routines
 obtain a pseudorandom number
 perform mathematical operations with two fixedpoint data types supported directly by the Operating System
 convert numeric variables of different types
You do not need any prior knowledge of the Operating System to read this chapter, which begins by describing the building blocks of memory in any operating system: bits, bytes, words, and long words. After subsequent discussions of the builtin compression and decompression routines provided by the Operating System, this chapter illustrates how you can use the Operating System's Mathematical and Logical Utilities. The chapter concludes with a reference to all mathematical and logical routines supported by the Operating System. If you are an experienced programmer, you might be able to skip directly to that section to determine which routine you need.
This chapter does not describe the numeric data types supported by the Standard Apple Numerics Environment (SANE) that the Operating System does not support directly. For more information on such data types, consult the Apple Numerics Manual and Inside Macintosh: PowerPC Numerics.
Chapter Contents
 About the Mathematical and Logical Utilities
 Bits, Bytes, Words, and Long Words
 Bit Manipulation and Logical Operations
 Reversed BitNumbering
 Data Compression
 Pseudorandom Number Generation
 FixedPoint Data Types
 AngleSlope Conversion
 Using the Mathematical and Logical Utilities
 Performing LowLevel Manipulation of Memory
 Testing and Manipulating Bits
 Performing Logical Operations on Long Words
 Extracting a Word From a Long Word
 Hardcoding Byte Values
 Compressing Data
 Obtaining Pseudorandom Numbers
 Using FixedPoint Data Types
 Mathematical and Logical Utilities Reference
 Data Structures
 64Bit Integer Record
 Routines
 Testing and Setting Bits
 Performing Logical Operations
 Getting and Setting Memory Values
 Compressing and Decompressing Data
 Obtaining a Pseudorandom Number
 Converting Between Angle and Slope Values
 Multiplying and Dividing FixedPoint Numbers
 Performing Calculations on FixedPoint Numbers
 Converting Among 32Bit Numeric Types
 Converting Between FixedPoint and FloatingPoint Values
 Converting Between FixedPoint and Integral Values
 Multiplying 32bit values
 Summary of the Mathematical and Logical Utilities
 Pascal Summary
 Data Types
 Routines
 C Summary
 Data Types
 Routines
 Global Variables
Get information on Apple products.
Visit the Apple Store online or at retail locations. 1800MYAPPLE Copyright © 2004 Apple Computer, Inc. All rights reserved.  Terms of use  Privacy Notice 