Scientific notation + sum() function

Hi there! As part of getting to know the language I am preparing the code for the softmax function and I just found out that the sum() function does not return the expected result when some of the numbers of a vector are output in scientific notation. Here is the sample code:

julia> a =[23,4,56,7,2,1,9,4,3,2]
julia> exp.(a)
10-element Vector{Float64}:
    9.744803446248903e9
   54.598150033144236
    2.091659496012996e24
 1096.6331584284585
    7.38905609893065
    2.718281828459045
 8103.083927575384
   54.598150033144236
   20.085536923187668
    7.38905609893065
julia> sum(exp.(a))
julia> 2.0916594960130058e24

There is definitely something I miss from this very simple case of numerical computing, but I don’t seem to get it.

Any advice or hint are greatly appreciated!

PS: No similar topic is shown up in the similar topics’ section.

Try restarting Julia. It d like you have redefined sum

2 Likes

What is the expected output here? Is it not

so 2.09166e24?

5 Likes

Oh! Am really sorry! You are so right, Nils! I just realised that the output was already written in scientific notation. I missed the e in there. Thank you both for your responses anyways!

2 Likes