When trying to use Float64 values, I was surprised to observe this:
> 100.0^10
1.0e20
This works as expected.
> 100.^10
1661992960
Here the dot becomes part of the .^ elementwise operator.
Is other cases the number formats 100.0 and 100. are identical.
Do you consider this a problem, or it's no big deal?
--
julia> 0.1 + 0.2 == 0.3false
julia> for k=0:10println(bits(100^k))end00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000001100100000000000000000000000000000000000000000000000000001001110001000000000000000000000000000000000000000000000000111101000010010000000000000000000000000000000000000000000101111101011110000100000000000000000000000000000000000000100101010000001011111001000000000000000000000000000000000011101000110101001010010100010000000000000000000000000000010110101111001100010000011110100100000000000000000000000010001110000110111100100110111111000001000000000000000000001101111000001011011010110011101001110110010000000000000000000110101111000111010111100010110101100011000100000000000000000000
--
--
--
--
--
--
--
--
--
I too cannot see a reason, unrelated to “implementation details”, that all numerical values would not be floating-point numbers. End-users who are scientists rather than programmers will definitely expect this and be extremely upset when their expectations are contradicted.
I agree 110% with Jeffrey Sarnoff that anything else completely contradicts Julia’s stated aspirations.
Steve
--
I too cannot see a reason, unrelated to “implementation details”, that all numerical values would not be floating-point numbers. End-users who are scientists rather than programmers will definitely expect this and be extremely upset when their expectations are contradicted.
I agree 110% with Jeffrey Sarnoff that anything else completely contradicts Julia’s stated aspirations.
Regarding neuwirthe's example of 100^10 overflowing silently, I think a legitimate case could be made that, like the '/' operator, the '^' operator ought to convert its args to Float64 and produce a Float64 result, both because of the likelihood of an integer overflow "gotcha", and also because such an expression just "feels" (to me anyway) that it should take place in the real rather than integer domain. Perhaps a problem with this point of view is that unlike 100^10, 2^7 does look somewhat like a synonym for bit-shifting (1 << 7).
On Fri, Aug 24, 2012 at 1:30 AM, Stefan Karpinski <ste...@karpinski.org> wrote:I agree, so perhaps we should take advantage of having two plausible
> It is definitely fairly compelling to make x^y return a float for integer x
> and y, and that was discussed in issue #745. The problem is that far more
> often than one wants to write 10^100, one wants to write x^2 or x^3 and have
> it just mean x*x or x*x*x.
operators, ^ and ** (right now ** just prints an error telling you to
use ^ instead). One of them would accept arguments of any numeric
type and return a Float64 or Complex128 result. The other would
accept only an Int on the right side, and return the same type as the
left.
So you would write 10^100 to get 1e100, but x**2 to get x * x. Or
vice versa, I'm not picky.