mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 14:40:30 +03:00
fix style in std.numeric
This commit is contained in:
parent
4cfa177fb5
commit
ce4f1692be
1 changed files with 45 additions and 43 deletions
|
@ -12,7 +12,7 @@ WIKI = Phobos/StdNumeric
|
||||||
Copyright: Copyright Andrei Alexandrescu 2008 - 2009.
|
Copyright: Copyright Andrei Alexandrescu 2008 - 2009.
|
||||||
License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
|
License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
|
||||||
Authors: $(WEB erdani.org, Andrei Alexandrescu),
|
Authors: $(WEB erdani.org, Andrei Alexandrescu),
|
||||||
Don Clugston, Robert Jacques
|
Don Clugston, Robert Jacques, Ilya Yaroshenko
|
||||||
Source: $(PHOBOSSRC std/_numeric.d)
|
Source: $(PHOBOSSRC std/_numeric.d)
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
|
@ -764,12 +764,12 @@ public:
|
||||||
|
|
||||||
/** Find a real root of a real function f(x) via bracketing.
|
/** Find a real root of a real function f(x) via bracketing.
|
||||||
*
|
*
|
||||||
* Given a function $(D f) and a range $(D [a..b]) such that $(D f(a))
|
* Given a function `f` and a range `[a..b]` such that `f(a)`
|
||||||
* and $(D f(b)) have opposite signs or at least one of them equals ±0,
|
* and `f(b)` have opposite signs or at least one of them equals ±0,
|
||||||
* returns the value of $(D x) in
|
* returns the value of `x` in
|
||||||
* the range which is closest to a root of $(D f(x)). If $(D f(x))
|
* the range which is closest to a root of `f(x)`. If `f(x)`
|
||||||
* has more than one root in the range, one will be chosen
|
* has more than one root in the range, one will be chosen
|
||||||
* arbitrarily. If $(D f(x)) returns NaN, NaN will be returned;
|
* arbitrarily. If `f(x)` returns NaN, NaN will be returned;
|
||||||
* otherwise, this algorithm is guaranteed to succeed.
|
* otherwise, this algorithm is guaranteed to succeed.
|
||||||
*
|
*
|
||||||
* Uses an algorithm based on TOMS748, which uses inverse cubic
|
* Uses an algorithm based on TOMS748, which uses inverse cubic
|
||||||
|
@ -777,7 +777,7 @@ public:
|
||||||
* or secant interpolation. Compared to TOMS748, this implementation
|
* or secant interpolation. Compared to TOMS748, this implementation
|
||||||
* improves worst-case performance by a factor of more than 100, and
|
* improves worst-case performance by a factor of more than 100, and
|
||||||
* typical performance by a factor of 2. For 80-bit reals, most
|
* typical performance by a factor of 2. For 80-bit reals, most
|
||||||
* problems require 8 to 15 calls to $(D f(x)) to achieve full machine
|
* problems require 8 to 15 calls to `f(x)` to achieve full machine
|
||||||
* precision. The worst-case performance (pathological cases) is
|
* precision. The worst-case performance (pathological cases) is
|
||||||
* approximately twice the number of bits.
|
* approximately twice the number of bits.
|
||||||
*
|
*
|
||||||
|
@ -819,10 +819,10 @@ T findRoot(T, DF)(scope DF f, in T a, in T b)
|
||||||
*
|
*
|
||||||
* f = Function to be analyzed
|
* f = Function to be analyzed
|
||||||
*
|
*
|
||||||
* ax = Left bound of initial range of $(D f) known to contain the
|
* ax = Left bound of initial range of `f` known to contain the
|
||||||
* root.
|
* root.
|
||||||
*
|
*
|
||||||
* bx = Right bound of initial range of $(D f) known to contain the
|
* bx = Right bound of initial range of `f` known to contain the
|
||||||
* root.
|
* root.
|
||||||
*
|
*
|
||||||
* fax = Value of $(D f(ax)).
|
* fax = Value of $(D f(ax)).
|
||||||
|
@ -840,7 +840,7 @@ T findRoot(T, DF)(scope DF f, in T a, in T b)
|
||||||
* Returns:
|
* Returns:
|
||||||
*
|
*
|
||||||
* A tuple consisting of two ranges. The first two elements are the
|
* A tuple consisting of two ranges. The first two elements are the
|
||||||
* range (in $(D x)) of the root, while the second pair of elements
|
* range (in `x`) of the root, while the second pair of elements
|
||||||
* are the corresponding function values at those points. If an exact
|
* are the corresponding function values at those points. If an exact
|
||||||
* root was found, both of the first two elements will contain the
|
* root was found, both of the first two elements will contain the
|
||||||
* root, and the second pair of elements will be 0.
|
* root, and the second pair of elements will be 0.
|
||||||
|
@ -1383,12 +1383,12 @@ unittest
|
||||||
}
|
}
|
||||||
|
|
||||||
/++
|
/++
|
||||||
Find a real minimum of a real function $(D f(x)) via bracketing.
|
Find a real minimum of a real function `f(x)` via bracketing.
|
||||||
Given a function $(D f) and a range $(D (ax..bx)),
|
Given a function `f` and a range `(ax..bx)`,
|
||||||
returns the value of $(D x) in the range which is closest to a minimum of $(D f(x)).
|
returns the value of `x` in the range which is closest to a minimum of `f(x)`.
|
||||||
$(D f) is never evaluted at the endpoints of $(D ax) and $(D bx).
|
`f` is never evaluted at the endpoints of `ax` and `bx`.
|
||||||
If $(D f(x)) has more than one minimum in the range, one will be chosen arbitrarily.
|
If `f(x)` has more than one minimum in the range, one will be chosen arbitrarily.
|
||||||
If $(D f(x)) returns NaN or -Infinity, $(D (x, f(x), NaN)) will be returned;
|
If `f(x)` returns NaN or -Infinity, `(x, f(x), NaN)` will be returned;
|
||||||
otherwise, this algorithm is guaranteed to succeed.
|
otherwise, this algorithm is guaranteed to succeed.
|
||||||
|
|
||||||
Params:
|
Params:
|
||||||
|
@ -1399,12 +1399,12 @@ Params:
|
||||||
absTolerance = Absolute tolerance.
|
absTolerance = Absolute tolerance.
|
||||||
|
|
||||||
Preconditions:
|
Preconditions:
|
||||||
$(D ax) and $(D bx) shall be finite reals. $(BR)
|
`ax` and `bx` shall be finite reals. $(BR)
|
||||||
$(D relTolerance) shall be normal positive real. $(BR)
|
$(D relTolerance) shall be normal positive real. $(BR)
|
||||||
$(D absTolerance) shall be normal positive real no less then $(D T.epsilon*2).
|
$(D absTolerance) shall be normal positive real no less then $(D T.epsilon*2).
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A tuple consisting of $(D x), $(D y = f(x)) and $(D error = 3 * (absTolerance * fabs(x) + relTolerance)).
|
A tuple consisting of `x`, `y = f(x)` and `error = 3 * (absTolerance * fabs(x) + relTolerance)`.
|
||||||
|
|
||||||
The method used is a combination of golden section search and
|
The method used is a combination of golden section search and
|
||||||
successive parabolic interpolation. Convergence is never much slower
|
successive parabolic interpolation. Convergence is never much slower
|
||||||
|
@ -1563,13 +1563,15 @@ body
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
unittest {
|
unittest
|
||||||
|
{
|
||||||
auto ret = findLocalMin((double x) => (x-4)^^2, -1e7, 1e7);
|
auto ret = findLocalMin((double x) => (x-4)^^2, -1e7, 1e7);
|
||||||
assert(ret.x.approxEqual(4.0));
|
assert(ret.x.approxEqual(4.0));
|
||||||
assert(ret.y.approxEqual(0.0));
|
assert(ret.y.approxEqual(0.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest {
|
unittest
|
||||||
|
{
|
||||||
import std.meta: AliasSeq;
|
import std.meta: AliasSeq;
|
||||||
foreach (T; AliasSeq!(double, float, real))
|
foreach (T; AliasSeq!(double, float, real))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue