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

Should we support Float#== ? #481

Open
st0012 opened this issue Oct 25, 2017 · 4 comments
Open

Should we support Float#== ? #481

st0012 opened this issue Oct 25, 2017 · 4 comments

Comments

@st0012
Copy link
Member

st0012 commented Oct 25, 2017

Float comparison is risky and is not a good practice, I think most programmers would agree this. So should we drop the support (or raise specialized error) when user calling this method, or we should just support it?

From my perspective supporting this method and telling user it's better not to use it against the core concept of Goby: No more best practices. So I don't want to support it actually, or at least change it to a special API so that user need to be aware what they're doing.

How do you think? @saveriomiroddi (actually @hachi8833 and @hanachin and me already have a discussion on Slack, so you can see what we already discussed in discussion channel).

@st0012
Copy link
Member Author

st0012 commented Oct 25, 2017

@hachi8833 Suggests that we can convert floats into rational. But how to implement this another question I think.

@st0012 st0012 added this to the version 0.2.0 milestone Oct 25, 2017
@Alexius-Huang
Copy link
Member

Maybe using the rat data type in Go to support float or rational type data directly to Goby?

@64kramsystem
Copy link
Member

64kramsystem commented Oct 25, 2017

This is an interesting idea, and somewhat audacious, but the consequences need to be extremely well thought out.

First, eliminating == implicitly eliminates also other arithmetic operators (>=, <=, !=).

Ultimately, floating point comparison is a legitimate operation (arguably dangerous, but still legitimate), so it's a matter of analyzing all the use cases.

For some cases, forcing precise arithmetic would require a considerable shift in mindset - this can be appropriate, but it requires careful design.

What would the users have to do when they need equality comparison?

Defaulting the number literals to precise (decimal) representation is interesting, but how would that affect arithmetic? What would 2.0 / 3 evaluate to? In scripting languages, the data type stays the same (eg. 1 / 3 = 0, and 1.0 / 3 = 0.333...), but there is no decimal representation of 2.0 / 3 - one would need to switch to rational, which evades this logic.

The idea it's interesting, but as I wrote, ultimately, you need to think 100000000000% the implications.

I think using rational numbers as default is not appropriate, since rational numbers are a related but different concept (see https://github.com/shopspring/decimal for examples).

@st0012
Copy link
Member Author

st0012 commented Oct 26, 2017

I think we should find some real world use cases of floats. Basically I only wrote web applications (or something relates to web applications) so I only have experience on decimal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants