Skip to content

Commit

Permalink
Remove integer domain example that doesn't work (#31298)
Browse files Browse the repository at this point in the history
* Update integer literal example to reflect smarter interpretation of exponents

* Drop mention of integer size

* Add an extra example of how to fix an exponent domain error

* Fix a sign error in documentation
  • Loading branch information
fredrikekre authored Mar 14, 2019
2 parents bd80892 + 5ccdc99 commit 4457264
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ to_power_type(x) = convert(Base._return_type(*, Tuple{typeof(x), typeof(x)}), x)
"\nConvert input to float.")))
@noinline throw_domerr_powbysq(::Integer, p) = throw(DomainError(p,
string("Cannot raise an integer x to a negative power ", p, '.',
"\nMake x a float by adding a zero decimal (e.g., 2.0^$p instead ",
"of 2^$p), or write 1/x^$(-p), float(x)^$p, or (x//1)^$p")))
"\nMake x or $p a float by adding a zero decimal ",
"(e.g., 2.0^$p or 2^$(float(p)) instead of 2^$p), ",
"or write 1/x^$(-p), float(x)^$p, x^float($p) or (x//1)^$p")))
@noinline throw_domerr_powbysq(::AbstractMatrix, p) = throw(DomainError(p,
string("Cannot raise an integer matrix x to a negative power ", p, '.',
"\nMake x a float matrix by adding a zero decimal ",
Expand Down
6 changes: 3 additions & 3 deletions doc/src/manual/noteworthy-differences.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ may trip up Julia users accustomed to MATLAB:
which grow `Vector`s much more efficiently than MATLAB's `a(end+1) = val`.
* The imaginary unit `sqrt(-1)` is represented in Julia as [`im`](@ref), not `i` or `j` as in MATLAB.
* In Julia, literal numbers without a decimal point (such as `42`) create integers instead of floating
point numbers. Arbitrarily large integer literals are supported. As a result, some operations
such as `2^-1` will throw a domain error as the result is not an integer (see [the FAQ entry on domain errors](@ref faq-domain-errors)
for details).
point numbers. As a result, some operations can throw
a domain error if they expect a float; for example, `julia> a = -1; 2^a` throws a domain error, as the
result is not an integer (see [the FAQ entry on domain errors](@ref faq-domain-errors) for details).
* In Julia, multiple values are returned and assigned as tuples, e.g. `(a, b) = (1, 2)` or `a, b = 1, 2`.
MATLAB's `nargout`, which is often used in MATLAB to do optional work based on the number of returned
values, does not exist in Julia. Instead, users can use optional and keyword arguments to achieve
Expand Down

0 comments on commit 4457264

Please sign in to comment.