📄 gsl-design.texi
字号:
achieve this, so prioritize testing on the critical parts and useinspection for the rest. Test all the error conditions by explicitlyprovoking them, because we consider it a serious defect if the functiondoes not return an error for an invalid parameter. N.B. Don't bother totest for null pointers -- it's sufficient for the library to segfault ifthe user provides an invalid pointer.The tests should be deterministic. Use the @code{gsl_test} functionsprovided to perform separate tests for each feature with a separateoutput PASS/FAIL line, so that any failure can be uniquely identified.Use realistic test cases with 'high entropy'. Tests on simple valuessuch as 1 or 0 may not reveal bugs. For example, a test using a valueof @math{x=1} will not pick up a missing factor of @math{x} in the code.Similarly, a test using a value of @math{x=0} will not pick any missingterms involving @math{x} in the code. Use values like @math{2.385} toavoid silent failures. If your test uses multiple values make sure there are no simplerelations between them that could allow bugs to be missed through silentcancellations.If you need some random floats to put in the test programs use @code{od -f/dev/random} as a source of inspiration.Don't use @code{sprintf} to create output strings in the tests. It cancause hard to find bugs in the test programs themselves. The functions@code{gsl_test_...} support format string arguments so use theseinstead.@node Compilation, Thread-safety, Test suites, Design@section CompilationMake sure everything compiles cleanly. Use the strict compilationoptions for extra checking.@smallexamplemake CFLAGS="-ansi -pedantic -Werror -W -Wall -Wtraditional -Wconversion -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wstrict-prototypes -fshort-enums -fno-common -Wmissing-prototypes -Wnested-externs -Dinline= -g -O4"@end smallexample@noindentAlso use @code{checkergcc} to check for memory problems on the stack andthe heap. It's the best memory checking tool. If checkergcc isn'tavailable then Electric Fence will check the heap, which is better thanno checking.There is a new tool @code{valgrind} for checking memory access. Testthe code with this as well.Make sure that the library will also compile with C++ compilers(g++). This should not be too much of a problem if you have been writingin ANSI C.@node Thread-safety, Legal issues, Compilation, Design@section Thread-safetyThe library should be usable in thread-safe programs. All the functionsshould be thread-safe, in the sense that they shouldn't use staticvariables.We don't require everything to be completely thread safe, but anythingthat isn't should be obvious. For example, some global variables areused to control the overall behavior of the library (range-checkingon/off, function to call on fatal error, etc). Since these are accesseddirectly by the user it is obvious to the multi-threaded programmer thatthey shouldn't be modified by different threads.There is no need to provide any explicit support for threads(e.g. locking mechanisms etc), just to avoid anything which would makeit impossible for someone to call a GSL routine from a multithreadedprogram.@node Legal issues, Non-UNIX portability, Thread-safety, Design@section Legal issues@itemize @bullet@itemEach contributor must make sure her code is under the GNU General PublicLicense (GPL). This means getting a disclaimer from your employer.@itemWe must clearly understand ownership of existing code and algorithms.@itemEach contributor can retain ownership of their code, or sign it over toFSF as they prefer. There is a standard disclaimer in the GPL (take a look at it). The morespecific you make your disclaimer the more likely it is that it will beaccepted by an employer. For example,@smallexampleYoyodyne, Inc., hereby disclaims all copyright interest in the software`GNU Scientific Library - Legendre Functions' (routines for computinglegendre functions numerically in C) written by James Hacker.<signature of Ty Coon>, 1 April 1989Ty Coon, President of Vice@end smallexample@item Obviously: don't use or translate non-free code. In particular don't copy or translate code from @cite{Numerical Recipes}or @cite{ACM TOMS}.Numerical Recipes is under a strict license and is not free software.The publishers Cambridge University Press claim copyright on all aspectsof the book and the code, including function names, variable names andordering of mathematical subexpressions. Routines in GSL should notrefer to Numerical Recipes or be based on it in any way. The ACM algorithms published in TOMS (Transactions on MathematicalSoftware) are not public domain, even though they are distributed on theinternet -- the ACM uses a special non-commercial license which is notcompatible with the GPL. The details of this license can be found on thecover page of ACM Transactions on Mathematical Software or on the ACMWebsite.Only use code which is explicitly under a free license: GPL or PublicDomain. If there is no license on the code then this does not mean itis public domain -- an explicit statement is required. If in doubt checkwith the author.@itemI @strong{think} one can reference algorithms from classic books onnumerical analysis (BJG: yes, provided the code is an independentimplementation and not copied from any existing software. Forexample, it would be ok to read the papers in ACM TOMS and make anindependent implementation from their description).@end itemize@node Non-UNIX portability, Compatibility with other libraries, Legal issues, Design@section Non-UNIX portabilityThere is good reason to make this library work on non-UNIX systems. Itis probably safe to ignore DOS and only worry about windows95/windowsNTportability (so filenames can be long, I think).On the other hand, nobody should be forced to use non-UNIX systems fordevelopment.The best solution is probably to issue guidelines for portability, likesaying "don't use XYZ unless you absolutely have to". Then the Windowspeople will be able to do their porting.@node Compatibility with other libraries, Parallelism, Non-UNIX portability, Design@section Compatibility with other librariesWe do not regard compatibility with other numerical libraries as apriority.However, other libraries, such as Numerical Recipes, are widely used.If somebody writes the code to allow drop-in replacement of theselibraries it would be useful to people. If it is done, it would be as aseparate wrapper that can be maintained and shipped separately.There is a separate issue of system libraries, such as BSD math libraryand functions like @code{expm1}, @code{log1p}, @code{hypot}. Thefunctions in this library are available on nearly every platform (butnot all). In this case, it is best to write code in terms of these nativefunctions to take advantage of the vendor-supplied system library (forexample log1p is a machine instruction on the Intel x86). The libraryalso provides portable implementations e.g. @code{gsl_hypot} which areused as an automatic fall back via autoconf when necessary. See theusage of @code{hypot} in @file{gsl/complex/math.c}, the implementationof @code{gsl_hypot} and the corresponding parts of files@file{configure.in} and @file{config.h.in} as an example.@node Parallelism, Precision, Compatibility with other libraries, Design@section ParallelismWe don't intend to provide support for parallelism within the libraryitself. A parallel library would require a completely different designand would carry overhead that other applications do not need.@node Precision, Miscellaneous, Parallelism, Design@section PrecisionFor algorithms which use cutoffs or other precision-related terms pleaseexpress these in terms of @code{GSL_DBL_EPSILON} and @code{GSL_DBL_MIN}, or powers orcombinations of these. This makes it easier to port the routines todifferent precisions.@node Miscellaneous, , Precision, Design@section MiscellaneousDon't use the letter @code{l} as a variable name --- it is difficult todistinguish from the number @code{1}. (This seems to be a favorite inold Fortran programs).Final tip: one perfect routine is better than any number of routinescontaining errors.@node Bibliography, Copying, Design, Top@chapter Bibliography @section General numerics@itemize@item@cite{Numerical Computation} (2 Volumes) by C.W. Ueberhuber,Springer 1997, ISBN 3540620583 (Vol 1) and ISBN 3540620575 (Vol 2).@item@cite{Accuracy and Stability of Numerical Algorithms} by N.J. Higham, SIAM, ISBN 0898715210.@item@cite{Sources and Development of Mathematical Software} edited by W.R. Cowell,Prentice Hall, ISBN 0138235015.@item@cite{A Survey of Numerical Mathematics (2 vols)} by D.M. Young and R.T. Gregory, ISBN 0486656918, ISBN 0486656926.@item@cite{Methods and Programs for Mathematical Functions} by Stephen L. Moshier,Hard to find (ISBN 13578980X or 0135789982, possibly others).@item@cite{Numerical Methods That Work} by Forman S. Acton, ISBN 0883854503.@item@cite{Real Computing Made Real: Preventing Errors in Scientific and Engineering Calculations} by Forman S. Acton, ISBN 0486442217. @end itemize@section Reference@itemize@item@cite{Handbook of Mathematical Functions} edited by Abramowitz & Stegun,Dover, ISBN 0486612724.@item@cite{The Art of Computer Programming} (3rd Edition, 3 Volumes) by D. Knuth,Addison Wesley, ISBN 0201485419.@end itemize@section Subject specific@itemize@item@cite{Matrix Computations} (3rd Ed) by G.H. Golub, C.F. Van Loan,Johns Hopkins University Press 1996, ISBN 0801854148.@item@cite{LAPACK Users' Guide} (3rd Edition),SIAM 1999, ISBN 0898714478.@item@cite{Treatise on the Theory of Bessel Functions 2ND Edition} by G N Watson, ISBN 0521483913.@item@cite{Higher Transcendental Functions satisfying nonhomogenous linear differential equations} by A W Babister, ISBN 1114401773.@end itemize@node Copying, GNU Free Documentation License, Bibliography, Top@unnumbered Copying The subroutines and source code in the @value{GSL} package are "free";this means that everyone is free to use them and free to redistributethem on a free basis. The @value{GSL}-related programs are not in thepublic domain; they are copyrighted and there are restrictions on theirdistribution, but these restrictions are designed to permit everythingthat a good cooperating citizen would want to do. What is not allowedis to try to prevent others from further sharing any version of theseprograms that they might get from you. Specifically, we want to make sure that you have the right to giveaway copies of the programs that relate to @value{GSL}, that you receivesource code or else can get it if you want it, that you can change theseprograms or use pieces of them in new free programs, and that you knowyou can do these things. To make sure that everyone has such rights, we have to forbid you todeprive anyone else of these rights. For example, if you distributecopies of the @value{GSL}-related code, you must give the recipients allthe rights that you have. You must make sure that they, too, receive orcan get the source code. And you must tell them their rights. Also, for our own protection, we must make certain that everyonefinds out that there is no warranty for the programs that relate to@value{GSL}. If these programs are modified by someone else and passedon, we want their recipients to know that what they have is not what wedistributed, so that any problems introduced by others will not reflecton our reputation. The precise conditions of the licenses for the programs currentlybeing distributed that relate to @value{GSL} are found in the GeneralPublic Licenses that accompany them.@node GNU Free Documentation License, , Copying, Top@unnumbered GNU Free Documentation License@include fdl.texi@c @printindex cp@c @node Function Index@c @unnumbered Function Index@c @printindex fn@c @node Variable Index@c @unnumbered Variable Index@c @printindex vr@c @node Type Index@c @unnumbered Type Index@c @printindex tp@bye
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -