dancasimiro / WAV.jl

Julia package for working with WAV files
Other
85 stars 35 forks source link

Add explicit `signed` conversion when loading signed negative values #22

Closed r9y9 closed 9 years ago

r9y9 commented 9 years ago

On the latest master, converting an (unsigned) negative value to a signed value such as convert(Int16, a::UInt64)seems to throw an InexactError.

julia> convert(Int16, uint(2^15) | ~unsigned(0) << 16)
-32768
julia> convert(Int16, uint(2^15) | ~unsigned(0) << 16)
ERROR: InexactError()
 in convert at int.jl:155

so we need to have explicit unsigned conversion using signed instead of converting it directly.

julia> convert(Int16, signed(uint(2^15) | ~unsigned(0) << 16))
-32768

I hope this fixes https://github.com/dancasimiro/WAV.jl/issues/21.

coveralls commented 9 years ago

Coverage Status

Coverage increased (+0.08%) to 63.83% when pulling e4b7d9d7a2ad8da02bc7efa5dd0204d93f663c14 on r9y9:fix-sign-extend-nagative-values into 00dfe9a37c86ccdf57cfd1b2e5ac70a2a6cae4eb on dancasimiro:master.

dancasimiro commented 9 years ago

I decided to go with the version that always calls "signed." See 9b7a6972cc5c701392ea6af687bcc20918ae400e

r9y9 commented 9 years ago

Looks good to me. Thanks