|
711 | 711 | eps() = eps(Float64)
|
712 | 712 | end
|
713 | 713 |
|
| 714 | +""" |
| 715 | + eps(::Type{T}) where T<:AbstractFloat |
| 716 | + eps() |
| 717 | +
|
| 718 | +Returns the *machine epsilon* of the floating point type `T` (`T = Float64` by |
| 719 | +default). This is defined as the gap between 1 and the next largest value representable by |
| 720 | +`T`, and is equivalent to `eps(one(T))`. |
| 721 | +
|
| 722 | +```jldoctest |
| 723 | +julia> eps() |
| 724 | +2.220446049250313e-16 |
| 725 | +
|
| 726 | +julia> eps(Float32) |
| 727 | +1.1920929f-7 |
| 728 | +
|
| 729 | +julia> 1.0 + eps() |
| 730 | +1.0000000000000002 |
| 731 | +
|
| 732 | +julia> 1.0 + eps()/2 |
| 733 | +1.0 |
| 734 | +``` |
| 735 | +""" |
| 736 | +eps(::Type{<:AbstractFloat}) |
| 737 | + |
| 738 | +""" |
| 739 | + eps(x::AbstractFloat) |
| 740 | +
|
| 741 | +Returns the *unit in last place* (ulp) of `x`. This is the distance between consecutive |
| 742 | +representable floating point values at `x`. In most cases, if the distance on either side |
| 743 | +of `x` is different, then the larger of the two is taken, that is |
| 744 | +
|
| 745 | + eps(x) == max(x-prevfloat(x), nextfloat(x)-x) |
| 746 | +
|
| 747 | +The exceptions to this rule are the smallest and largest finite values |
| 748 | +(e.g. `nextfloat(-Inf)` and `prevfloat(Inf)` for `Float64`), which round to the smaller of |
| 749 | +the values. |
| 750 | +
|
| 751 | +The rationale for this behavior is that `eps` bounds the floating point rounding |
| 752 | +error. Under the default `RoundNearest` rounding mode, if ``y`` is a real number and ``x`` |
| 753 | +is the nearest floating point number to ``y``, then |
| 754 | +
|
| 755 | +```math |
| 756 | +|y-x| \\leq \\operatorname{eps}(x)/2. |
| 757 | +``` |
| 758 | +
|
| 759 | +```jldoctest |
| 760 | +julia> eps(1.0) |
| 761 | +2.220446049250313e-16 |
| 762 | +
|
| 763 | +julia> eps(prevfloat(2.0)) |
| 764 | +2.220446049250313e-16 |
| 765 | +
|
| 766 | +julia> eps(2.0) |
| 767 | +4.440892098500626e-16 |
| 768 | +
|
| 769 | +julia> x = prevfloat(Inf) # largest finite Float64 |
| 770 | +1.7976931348623157e308 |
| 771 | +
|
| 772 | +julia> x + eps(x)/2 # rounds up |
| 773 | +Inf |
| 774 | +
|
| 775 | +julia> x + prevfloat(eps(x)/2) # rounds down |
| 776 | +1.7976931348623157e308 |
| 777 | +``` |
| 778 | +""" |
| 779 | +eps(::AbstractFloat) |
| 780 | + |
| 781 | + |
714 | 782 | ## byte order swaps for arbitrary-endianness serialization/deserialization ##
|
715 | 783 | bswap(x::Float32) = bswap_int(x)
|
716 | 784 | bswap(x::Float64) = bswap_int(x)
|
|
0 commit comments