1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use ;
use Float;
use ;
/// Find the square root of a given `radicand` to within a given `acceptable_err`
/// by the Newton-Rahpson method, using the initial guess `x0`. If, after
/// `max_iterations`, the error is not less than the give `acceptable_err`,
/// `None` is returned.
///
/// # Examples
///
/// ```
/// use nrfind::find_sqrt;
///
/// let precision = 0.1;
/// let iterations = 100;
/// let radicand = 25.6;
/// let guess = 10.0;
///
/// // This will produce a close approximation of the actual square root
/// let value = find_sqrt(radicand, guess, precision, iterations).unwrap();
///
/// let actual: f64 = 5.0497;
/// let difference = (value - actual).abs();
///
/// assert!(difference < precision);
///
/// // This will fail, as there is no real solution.
/// let value = find_sqrt(-radicand, guess, precision, iterations);
/// value.unwrap_err();
/// ```
///