📄 usage.texi
字号:
If the form @code{extern inline} causes problems with other compilers astricter autoconf test can be used, see @ref{Autoconf Macros}.@node Long double@section Long double@cindex long doubleThe extended numerical type @code{long double} is part of the ANSI Cstandard and should be available in every modern compiler. However, theprecision of @code{long double} is platform dependent, and this shouldbe considered when using it. The IEEE standard only specifies theminimum precision of extended precision numbers, while the precision of@code{double} is the same on all platforms.In some system libraries the @code{stdio.h} formatted input/outputfunctions @code{printf} and @code{scanf} are not implemented correctlyfor @code{long double}. Undefined or incorrect results are avoided bytesting these functions during the @code{configure} stage of librarycompilation and eliminating certain GSL functions which depend on themif necessary. The corresponding line in the @code{configure} outputlooks like this,@examplechecking whether printf works with long double... no@end example@noindentConsequently when @code{long double} formatted input/output does notwork on a given system it should be impossible to link a program whichuses GSL functions dependent on this.If it is necessary to work on a system which does not support formatted@code{long double} input/output then the options are to use binaryformats or to convert @code{long double} results into @code{double} forreading and writing.@node Portability functions@section Portability functionsTo help in writing portable applications GSL provides someimplementations of functions that are found in other libraries, such asthe BSD math library. You can write your application to use the nativeversions of these functions, and substitute the GSL versions via apreprocessor macro if they are unavailable on another platform. For example, after determining whether the BSD function @code{hypot} isavailable you can include the following macro definitions in a file@file{config.h} with your application,@example/* Substitute gsl_hypot for missing system hypot */#ifndef HAVE_HYPOT#define hypot gsl_hypot#endif@end example@noindentThe application source files can then use the include command@code{#include <config.h>} to replace each occurrence of @code{hypot} by@code{gsl_hypot} when @code{hypot} is not available. This substitutioncan be made automatically if you use @code{autoconf}, see @ref{AutoconfMacros}.In most circumstances the best strategy is to use the native versions ofthese functions when available, and fall back to GSL versions otherwise,since this allows your application to take advantage of anyplatform-specific optimizations in the system library. This is thestrategy used within GSL itself.@node Alternative optimized functions@section Alternative optimized functions@cindex alternative optimized functions@cindex optimized functions, alternativesThe main implementation of some functions in the library will not beoptimal on all architectures. For example, there are several ways tocompute a Gaussian random variate and their relative speeds areplatform-dependent. In cases like this the library provides alternativeimplementations of these functions with the same interface. If youwrite your application using calls to the standard implementation youcan select an alternative version later via a preprocessor definition.It is also possible to introduce your own optimized functions this waywhile retaining portability. The following lines demonstrate the use ofa platform-dependent choice of methods for sampling from the Gaussiandistribution,@example#ifdef SPARC#define gsl_ran_gaussian gsl_ran_gaussian_ratio_method#endif#ifdef INTEL#define gsl_ran_gaussian my_gaussian#endif@end example@noindentThese lines would be placed in the configuration header file@file{config.h} of the application, which should then be included by allthe source files. Note that the alternative implementations will notproduce bit-for-bit identical results, and in the case of random numberdistributions will produce an entirely different stream of randomvariates.@node Support for different numeric types@section Support for different numeric typesMany functions in the library are defined for different numeric types.This feature is implemented by varying the name of the function with atype-related modifier---a primitive form of C++ templates. Themodifier is inserted into the function name after the initial moduleprefix. The following table shows the function names defined for allthe numeric types of an imaginary module @code{gsl_foo} with function@code{fn},@examplegsl_foo_fn double gsl_foo_long_double_fn long double gsl_foo_float_fn float gsl_foo_long_fn long gsl_foo_ulong_fn unsigned long gsl_foo_int_fn int gsl_foo_uint_fn unsigned int gsl_foo_short_fn short gsl_foo_ushort_fn unsigned shortgsl_foo_char_fn char gsl_foo_uchar_fn unsigned char @end example@noindentThe normal numeric precision @code{double} is considered the default anddoes not require a suffix. For example, the function@code{gsl_stats_mean} computes the mean of double precision numbers,while the function @code{gsl_stats_int_mean} computes the mean ofintegers.A corresponding scheme is used for library defined types, such as@code{gsl_vector} and @code{gsl_matrix}. In this case the modifier isappended to the type name. For example, if a module defines a newtype-dependent struct or typedef @code{gsl_foo} it is modified for othertypes in the following way,@examplegsl_foo double gsl_foo_long_double long double gsl_foo_float float gsl_foo_long long gsl_foo_ulong unsigned long gsl_foo_int int gsl_foo_uint unsigned int gsl_foo_short short gsl_foo_ushort unsigned shortgsl_foo_char char gsl_foo_uchar unsigned char @end example@noindentWhen a module contains type-dependent definitions the library providesindividual header files for each type. The filenames are modified asshown in the below. For convenience the default header includes thedefinitions for all the types. To include only the double precisionheader file, or any other specific type, use its individual filename.@example#include <gsl/gsl_foo.h> All types#include <gsl/gsl_foo_double.h> double #include <gsl/gsl_foo_long_double.h> long double #include <gsl/gsl_foo_float.h> float #include <gsl/gsl_foo_long.h> long #include <gsl/gsl_foo_ulong.h> unsigned long #include <gsl/gsl_foo_int.h> int #include <gsl/gsl_foo_uint.h> unsigned int #include <gsl/gsl_foo_short.h> short #include <gsl/gsl_foo_ushort.h> unsigned short#include <gsl/gsl_foo_char.h> char #include <gsl/gsl_foo_uchar.h> unsigned char @end example@node Compatibility with C++@section Compatibility with C++@cindex C++, compatibilityThe library header files automatically define functions to have@code{extern "C"} linkage when included in C++ programs. This allowsthe functions to be called directly from C++.To use C++ exception handling within user-defined functions passed tothe library as parameters, the library must be built with theadditional @code{CFLAGS} compilation option @option{-fexceptions}.@node Aliasing of arrays@section Aliasing of arrays@cindex aliasing of arraysThe library assumes that arrays, vectors and matrices passed asmodifiable arguments are not aliased and do not overlap with each other.This removes the need for the library to handle overlapping memoryregions as a special case, and allows additional optimizations to beused. If overlapping memory regions are passed as modifiable argumentsthen the results of such functions will be undefined. If the argumentswill not be modified (for example, if a function prototype declares themas @code{const} arguments) then overlapping or aliased memory regionscan be safely used.@node Thread-safety@section Thread-safetyThe library can be used in multi-threaded programs. All the functionsare thread-safe, in the sense that they do not use static variables.Memory is always associated with objects and not with functions. Forfunctions which use @dfn{workspace} objects as temporary storage theworkspaces should be allocated on a per-thread basis. For functionswhich use @dfn{table} objects as read-only memory the tables can be usedby multiple threads simultaneously. Table arguments are always declared@code{const} in function prototypes, to indicate that they may besafely accessed by different threads.There are a small number of static global variables which are used tocontrol the overall behavior of the library (e.g. whether to userange-checking, the function to call on fatal error, etc). Thesevariables are set directly by the user, so they should be initializedonce at program startup and not modified by different threads.@node Deprecated Functions@section Deprecated Functions@cindex deprecated functionsFrom time to time, it may be necessary for the definitions of somefunctions to be altered or removed from the library. In thesecircumstances the functions will first be declared @dfn{deprecated} andthen removed from subsequent versions of the library. Functions thatare deprecated can be disabled in the current release by setting thepreprocessor definition @code{GSL_DISABLE_DEPRECATED}. This allowsexisting code to be tested for forwards compatibility.@node Code Reuse@section Code Reuse@cindex code reuse in applications@cindex source code, reuse in applicationsWhere possible the routines in the library have been written to avoiddependencies between modules and files. This should make it possible toextract individual functions for use in your own applications, withoutneeding to have the whole library installed. You may need to definecertain macros such as @code{GSL_ERROR} and remove some @code{#include}statements in order to compile the files as standalone units. Reuse ofthe library code in this way is encouraged, subject to the terms of theGNU General Public License.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -