Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of a decimal point to show Floats ambiguous #3777

Closed
IainNZ opened this issue Jul 20, 2013 · 6 comments
Closed

Use of a decimal point to show Floats ambiguous #3777

IainNZ opened this issue Jul 20, 2013 · 6 comments

Comments

@IainNZ
Copy link
Member

IainNZ commented Jul 20, 2013

type Vec
x::Float64
y::Float64
z::Float64
end

a = Vec(1., 2., 3.)
_(a::Int64, b::Vec) = Vec(a_b.x, a_b.y, a_b.z)
_(a::Float64, b::Vec) = Vec(a_b.x, a_b.y, a_b.z)

println(1_a)
println(2.5_a)
println(1.a) # This line fails with ERROR: no method .(Int64,Vec)

@JeffBezanson
Copy link
Sponsor Member

There doesn't seem to be a definition of .*

@IainNZ
Copy link
Member Author

IainNZ commented Jul 20, 2013

Right good point. I guess my confusion stems from how it often seems to be acceptable to use 1. to mean a Float, but here that breaks down. Confusing behaviour?

@mlubin
Copy link
Member

mlubin commented Jul 20, 2013

This could be a tricky point for beginners, but I think it's worth it to be able to use 1. as a float constant.

@JeffBezanson
Copy link
Sponsor Member

We deliberately decided to resolve the ambiguous case 1.*x as 1 .* x, since if x is float it makes basically no difference, but if x were integer we wouldn't want 1.*x to spuriously promote to float.

@johnmyleswhite
Copy link
Member

One thing we could do to make this a little better is to put a comment in the style guide advocating whitespace around operators, which is what Google partially recommends for languages like Python and R: https://google-styleguide.googlecode.com/svn/trunk/pyguide.html

This won't resolve the issue, but discourages ambiguity.

@tomasaschan
Copy link
Member

Isn't there an ambiguity warning that could be issued here? I do agree that the current behavior makes sense, but printing a warning message that this is ambiguous, and that it's better to write either 1. * x or 1.0 * x to avoid the ambiguity, would be very helpful.

KristofferC added a commit that referenced this issue Feb 8, 2024
…53220)

Replaces #53216 (I can't push to
that repo branch)

Adds
- making pkgimages for REPLExt
- Fixes PkgCompletionProvider location

Stdlib: Pkg
URL: https://github.com/JuliaLang/Pkg.jl.git
Stdlib branch: master
Julia branch: master
Old commit: f3b81f1aa
New commit: 6dd0e7c9e
Julia version: 1.11.0-DEV
Pkg version: 1.11.0
Bump invoked by: @IanButterworth
Powered by:
[BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl)

Diff:
JuliaLang/Pkg.jl@f3b81f1...6dd0e7c

```
$ git log --oneline f3b81f1aa..6dd0e7c9e
6dd0e7c9e Revert "add test for recurring precompile" (#3779)
dbf114fa9 Merge pull request #3777 from JuliaLang/kc/repl_extension
a49d47981 fixup
e3edf3917 avoid prompting for git creds on CI (#3778)
510454343 make the `REPL` specific code into an extension
12d2de14e make `pkgstr` independent of REPL
```

---------

Co-authored-by: Dilum Aluthge <[email protected]>
Co-authored-by: Valentin Churavy <[email protected]>
Co-authored-by: Kristoffer Carlsson <[email protected]>
Co-authored-by: Jameson Nash <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants