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

FEATURE REQUEST: Add a "roughly" operator #743

Open
janetacarr opened this issue Sep 21, 2024 · 7 comments
Open

FEATURE REQUEST: Add a "roughly" operator #743

janetacarr opened this issue Sep 21, 2024 · 7 comments

Comments

@janetacarr
Copy link

It might be useful to have an operator that says something is roughly like something else:

3.14 === ~3 ;; true
3 === ~3.14 ;; true
2 + 2 == ~5 ;; true for large values of two

The precise definition of roughly should depend an a Quantum Random Number Generator so the universe can decide whether or not this is truly roughly equal to the other operand.

@guigui0246
Copy link

Don't forget that 3.14 ~ 3 should be the same as 3.14 = ~3 and 2 + 2 ~~ 5 the same as 2 + 2 == ~5.
Also don't forget that ~ 3.14 3 should be the same as ~3.14 = 3 and different from 3.14 ~ 3

@Darvass69
Copy link

I think we already have something like that.
https://github.com/TodePond/DreamBerd?tab=readme-ov-file#equality

If you want to be much less precise, you can use =.

3 = 3.14! //true

@guigui0246
Copy link

I think we already have something like that. https://github.com/TodePond/DreamBerd?tab=readme-ov-file#equality

If you want to be much less precise, you can use =.

3 = 3.14! //true

It's a less precise equal not a roughly equal
exemples:

print 3 = 3 ! // true
print 3 ~ 3 ! // false because roughly is not equal
if 3 = 3.14 {
print 3.1 ! // 3.1
print 3 ! // 3.14
}
if 3 ~ 3.14 {
print 3.1 ! // 3.14
print 3 ! // 3
}

@Darvass69
Copy link

I don't understand what you mean here.

if 3 = 3.14 {
print 3.1 ! // 3.1
print 3 ! // 3.14
}
if 3 ~ 3.14 {
print 3.1 ! // 3.14
print 3 ! // 3
}

Why does 3 = 3.14 makes it so that print 3 prints '3.14'?
Why does 3 ~ 3.14 makes it so that print 3.1 prints '3.14'?

Also if you want to do print 3 ~ 3 ! // false, just do 3 = 3 && 3 ;= 3 and you get the same thing.

@guigui0246
Copy link

Also if you want to do print 3 ~ 3 ! // false, just do 3 = 3 && 3 ;= 3 and you get the same thing.

const const n = 3!
print 3 ~ n ! //false
print 3 = n && 3 ;= n ! // false
const const n = 3.1!
print 3 ~ n ! //true
print 3 = n && 3 ;= n ! // false

@guigui0246
Copy link

About the other I was wrong for the second if (it's how it would work for ~ 3 = 3.14)

3 = 3.14 ! // Now the variable 3 is set to 3.14 so `print 3` prints `3.14`
3 ~ 3.14 ! // Now the variable 3 is roughly set to 3.14 so `print 3` prints a number close to 3.14 (like `3.1` or `3.1654`) 
~ 3 = 3.14! // Now the variables of value around 3 (like `3.1` or `2.98`) are set to 3.14 so `print 3.1` prints `3.14`
~ 2 ~ 3.14! // Now the variables of value around 3 (like `3.1` or `2.98`) are roughly set to 3.14 so `print 2.98` could print `3.1654`

@Darvass69
Copy link

Are you proposing something that is both a comparator and an assignment at the same time?

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

3 participants