product of Int64 and Float64 is Int64

167 views
Skip to first unread message

Michele Zaffalon

unread,
Oct 19, 2016, 7:11:38 AM10/19/16
to julia-users
I am confused by the type of the result of `1.*80`, which is `Int64`, despite the fact that `1.` is `Float64`, and that `Float64(1)*80` is a `Float64`:

julia> typeof(1.), typeof(80), typeof(1.*80), typeof(Float64(1.)*80)
(Float64,Int64,Int64,Float64)

Does it have to do with the fact that both 1 and 80 have an exact Float64 representation?

julia> bits(1.)
"0011111111110000000000000000000000000000000000000000000000000000"

julia
> bits(80.)
"0100000001010100000000000000000000000000000000000000000000000000"


Thank you,
michele

Mauro

unread,
Oct 19, 2016, 7:30:27 AM10/19/16
to julia...@googlegroups.com
On Wed, 2016-10-19 at 13:11, Michele Zaffalon <michele....@gmail.com> wrote:
> I am confused by the type of the result of `1.*80`, which is `Int64`, despite
> the fact that `1.` is `Float64`, and that `Float64(1)*80` is a `Float64`:

No this is parsed as 1 .* 80. Try 1.0*80

Michele Zaffalon

unread,
Oct 19, 2016, 7:36:00 AM10/19/16
to julia-users
I should have realized that:

julia> promote(1., 80)
(1.0,80.0)
julia
> 80*1.
80.0

Thank you.

Michele Zaffalon

unread,
Oct 19, 2016, 7:36:58 AM10/19/16
to julia-users
And

julia> parse("1.*80")
:(1 .* 80)
julia
> parse("1.0*80")
:(1.0 * 80)

lapeyre....@gmail.com

unread,
Oct 19, 2016, 7:46:23 AM10/19/16
to julia-users
Or include a space. 

parse("1. * 80") --> :(1.0 * 80)

parse("1.* 80")  --> :(1 .* 80)


On Wednesday, October 19, 2016 at 1:30:27 PM UTC+2, Mauro wrote:

Michele Zaffalon

unread,
Oct 19, 2016, 8:08:30 AM10/19/16
to julia...@googlegroups.com
Thanks.

Krisztián Pintér

unread,
Oct 19, 2016, 9:53:00 AM10/19/16
to julia-users

i know i shouldn't, but i'm kinda angry at this "1." notation. saving one character really worth losing readability? also leading to errors like this. personally, i would not even allow this syntax at all.

Tamas Papp

unread,
Oct 19, 2016, 10:24:54 AM10/19/16
to julia...@googlegroups.com
And the same goes for the closely related .1 syntax.

Perhaps you could create an issue, if there isn't one already?

Steven G. Johnson

unread,
Oct 19, 2016, 10:25:19 AM10/19/16
to julia-users


On Wednesday, October 19, 2016 at 9:53:00 AM UTC-4, Krisztián Pintér wrote:

i know i shouldn't, but i'm kinda angry at this "1." notation. saving one character really worth losing readability? also leading to errors like this. personally, i would not even allow this syntax at all.

Steven G. Johnson

unread,
Oct 19, 2016, 10:41:16 AM10/19/16
to julia-users

Steven Sagaert

unread,
Oct 19, 2016, 11:40:35 AM10/19/16
to julia-users
agreed

Michele Zaffalon

unread,
Oct 19, 2016, 3:25:13 PM10/19/16
to julia...@googlegroups.com
A bad habit learnt using Python...
Reply all
Reply to author
Forward
0 new messages