Sun Logo


Numerical Computation Guide

Suntrademark Studio 9

817-6702-10



Contents

Figures

Tables

Before You Begin

Who Should Use This Book

How This Book Is Organized

Typographic Conventions

Shell Prompts

Accessing Sun Studio Software and Man Pages

Accessing Compilers and Tools Documentation

Accessing Related Solaris Documentation

Resources for Developers

Contacting Sun Technical Support

Sun Welcomes Your Comments

1. Introduction

1.1 Floating-Point Environment

2. IEEE Arithmetic

2.1 IEEE Arithmetic Model

2.1.1 What Is IEEE Arithmetic?

2.2 IEEE Formats

2.2.1 Storage Formats

2.2.2 Single Format

2.2.3 Double Format

2.2.4 Double-Extended Format (SPARC)

2.2.5 Double-Extended Format (x86)

2.2.6 Ranges and Precisions in Decimal Representation

2.2.7 Base Conversion in the Solaris Environment

2.3 Underflow

2.3.1 Underflow Thresholds

2.3.2 How Does IEEE Arithmetic Treat Underflow?

2.3.3 Why Gradual Underflow?

2.3.4 Error Properties of Gradual Underflow

2.3.5 Two Examples of Gradual Underflow Versus Store 0

2.3.6 Does Underflow Matter?

3. The Math Libraries

3.1 Standard Math Library

3.2 Additional Math Libraries

3.2.1 Sun Math Library

3.2.2 Optimized Libraries

3.2.3 Vector Math Library (SPARC only)

3.2.4 libm9x Math Library

3.3 Single, Double, and Long Double Precision

3.4 IEEE Support Functions

3.4.1 ieee_functions(3m) and ieee_sun(3m)

3.4.2 ieee_values(3m)

3.4.3 ieee_flags(3m)

3.4.4 ieee_retrospective(3m)

3.4.5 nonstandard_arithmetic(3m)

3.5 C99 Floating Point Environment Functions

3.5.1 Exception Flag Functions

3.5.2 Rounding Control

3.5.3 Environment Functions

3.6 Implementation Features of libm and libsunmath

3.6.1 About the Algorithms

3.6.2 Argument Reduction for Trigonometric Functions

3.6.3 Data Conversion Routines

3.6.4 Random Number Facilities

4. Exceptions and Exception Handling

4.1 What Is an Exception?

4.1.1 Notes for Table 4-1

4.2 Detecting Exceptions

4.2.1 ieee_flags(3m)

4.2.2 C99 Exception Flag Functions

4.3 Locating an Exception

4.3.1 Using the Debuggers to Locate an Exception

4.3.2 Using a Signal Handler to Locate an Exception

4.3.3 Using libm9x.so Exception Handling Extensions to Locate an Exception

4.4 Handling Exceptions

A. Examples

A.1 IEEE Arithmetic

A.2 The Math Libraries

A.2.1 Random Number Generator

A.2.2 IEEE Recommended Functions

A.2.3 IEEE Special Values

A.2.4 ieee_flags -- Rounding Direction

A.2.5 C99 Floating Point Environment Functions

A.3 Exceptions and Exception Handling

A.3.1 ieee_flags -- Accrued Exceptions

A.3.2 ieee_handler -- Trapping Exceptions

A.3.3 ieee_handler -- Abort on Exceptions

A.3.4 libm9x.so Exception Handling Features

A.3.5 Using libm9x.so With Fortran Programs

A.4 Miscellaneous

A.4.1 sigfpe -- Trapping Integer Exceptions

A.4.2 Calling Fortran From C

A.4.3 Useful Debugging Commands

B. SPARC Behavior and Implementation

B.1 Floating-Point Hardware

B.1.1 Floating-Point Status Register and Queue

B.1.2 Special Cases Requiring Software Support

B.2 fpversion(1) Function -- Finding Information About the FPU

C. x86 Behavior and Implementation

D. What Every Computer Scientist Should Know About Floating-Point Arithmetic

D.1 Abstract

D.2 Introduction

D.3 Rounding Error

D.3.1 Floating-point Formats

D.3.2 Relative Error and Ulps

D.3.3 Guard Digits

D.3.4 Cancellation

D.3.5 Exactly Rounded Operations

D.4 The IEEE Standard

D.4.1 Formats and Operations

D.4.2 Special Quantities

D.4.3 NaNs

D.4.4 Exceptions, Flags and Trap Handlers

D.5 Systems Aspects

D.5.1 Instruction Sets

D.5.2 Languages and Compilers

D.5.3 Exception Handling

D.6 The Details

D.6.1 Rounding Error

D.6.2 Binary to Decimal Conversion

D.6.3 Errors In Summation

D.7 Summary

D.8 Acknowledgments

D.9 References

D.10 Theorem 14 and Theorem 8

D.10.1 Theorem 14

D.10.2 Proof

D.11 Differences Among IEEE 754 Implementations

D.11.1 Current IEEE 754 Implementations

D.11.2 Pitfalls in Computations on Extended-Based Systems

D.11.3 Programming Language Support for Extended Precision

D.11.4 Conclusion

E. Standards Compliance

E.1 SVID History

E.2 IEEE 754 History

E.3 SVID Future Directions

E.4 SVID Implementation

E.4.1 General Notes on Exceptional Cases and libm Functions

E.4.2 Notes on libm

E.5 LIA-1 Conformance

F. References

F.1 Chapter 2: "IEEE Arithmetic"

F.2 Chapter 3: "The Math Libraries"

F.3 Chapter 4: "Exceptions and Signal Handling"

F.4 Appendix B: "SPARC Behavior and Implementation"

F.5 Standards

F.6 Test Programs

Glossary

Index