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

ceil/floor bug with negative floats #382

Closed
gromgit opened this issue Jul 28, 2020 · 2 comments
Closed

ceil/floor bug with negative floats #382

gromgit opened this issue Jul 28, 2020 · 2 comments
Milestone

Comments

@gromgit
Copy link
Contributor

gromgit commented Jul 28, 2020

> -10.6.ceil()
-11   # should be -10
> -10.6.floor()
-10   # should be -11
> -10.6.round()
-11
> -10.6.int()
-10
@odino
Copy link
Collaborator

odino commented Jul 28, 2020 via email

@gromgit
Copy link
Contributor Author

gromgit commented Jul 28, 2020

👍, parenthesizing the negative number object gives correct results for all the math operations in both my PRs, so it just a parser issue.

odino added a commit that referenced this issue Jul 28, 2020
This bugfix introduces negative numbers into our parser:
before, -10 would be parsed as (minus, number) whereas
right now it's going to be parsed as (number) only.

This fixes a bug with precedences, where `-1.str()`
would be parsed as (-, (1, str)), leading to first
calling the str method on the positive number, then
applying the minus.

Before:

```
⧐  -1.234.str()
ERROR: unknown operator: -STRING
	[1:1]	-1.234.str()

```

After:

```
⧐  -1.234.str()
-1.234
```

If a space is found between the minus and the number,
the old parsing mechanism still applies.

I found inspiration in Ruby, where:

```
$ - 1.to_s()
-@: undefined method `-@' for "1":String

$-1.to_s()
-1

$ -10.3.floor()
-11

$ - 10.3.floor()
-10
```
@odino odino added this to the 2.2.x milestone Jul 28, 2020
odino added a commit that referenced this issue Jul 28, 2020
This bugfix introduces negative numbers into our parser:
before, -10 would be parsed as (minus, number) whereas
right now it's going to be parsed as (number) only.

This fixes a bug with precedences, where `-1.str()`
would be parsed as (-, (1, str)), leading to first
calling the str method on the positive number, then
applying the minus.

Before:

```
⧐  -1.234.str()
ERROR: unknown operator: -STRING
	[1:1]	-1.234.str()

```

After:

```
⧐  -1.234.str()
-1.234
```

If a space is found between the minus and the number,
the old parsing mechanism still applies.

I found inspiration in Ruby, where:

```
$ - 1.to_s()
-@: undefined method `-@' for "1":String

$-1.to_s()
-1

$ -10.3.floor()
-11

$ - 10.3.floor()
-10
```
odino added a commit that referenced this issue Jul 28, 2020
This bugfix introduces negative numbers into our parser:
before, -10 would be parsed as (minus, number) whereas
right now it's going to be parsed as (number) only.

This fixes a bug with precedences, where `-1.str()`
would be parsed as (-, (1, str)), leading to first
calling the str method on the positive number, then
applying the minus.

Before:

```
⧐  -1.234.str()
ERROR: unknown operator: -STRING
	[1:1]	-1.234.str()

```

After:

```
⧐  -1.234.str()
-1.234
```

If a space is found between the minus and the number,
the old parsing mechanism still applies.

I found inspiration in Ruby, where:

```
$ - 1.to_s()
-@: undefined method `-@' for "1":String

$-1.to_s()
-1

$ -10.3.floor()
-11

$ - 10.3.floor()
-10
```
odino added a commit that referenced this issue Jul 28, 2020
This bugfix introduces negative numbers into our parser:
before, -10 would be parsed as (minus, number) whereas
right now it's going to be parsed as (number) only.

This fixes a bug with precedences, where `-1.str()`
would be parsed as (-, (1, str)), leading to first
calling the str method on the positive number, then
applying the minus.

Before:

```
⧐  -1.234.str()
ERROR: unknown operator: -STRING
	[1:1]	-1.234.str()

```

After:

```
⧐  -1.234.str()
-1.234
```

If a space is found between the minus and the number,
the old parsing mechanism still applies.

I found inspiration in Ruby, where:

```
$ - 1.to_s()
-@: undefined method `-@' for "1":String

$-1.to_s()
-1

$ -10.3.floor()
-11

$ - 10.3.floor()
-10
```
odino added a commit that referenced this issue Jul 28, 2020
This bugfix introduces negative numbers into our parser:
before, -10 would be parsed as (minus, number) whereas
right now it's going to be parsed as (number) only.

This fixes a bug with precedences, where `-1.str()`
would be parsed as (-, (1, str)), leading to first
calling the str method on the positive number, then
applying the minus.

Before:

```
⧐  -1.234.str()
ERROR: unknown operator: -STRING
	[1:1]	-1.234.str()

```

After:

```
⧐  -1.234.str()
-1.234
```

If a space is found between the minus and the number,
the old parsing mechanism still applies.

I found inspiration in Ruby, where:

```
$ - 1.to_s()
-@: undefined method `-@' for "1":String

$-1.to_s()
-1

$ -10.3.floor()
-11

$ - 10.3.floor()
-10
```
odino added a commit that referenced this issue Jul 28, 2020
This bugfix introduces negative numbers into our parser:
before, -10 would be parsed as (minus, number) whereas
right now it's going to be parsed as (number) only.

This fixes a bug with precedences, where `-1.str()`
would be parsed as (-, (1, str)), leading to first
calling the str method on the positive number, then
applying the minus.

Before:

```
⧐  -1.234.str()
ERROR: unknown operator: -STRING
	[1:1]	-1.234.str()

```

After:

```
⧐  -1.234.str()
-1.234
```

If a space is found between the minus and the number,
the old parsing mechanism still applies.

I found inspiration in Ruby, where:

```
$ - 1.to_s()
-@: undefined method `-@' for "1":String

$-1.to_s()
-1

$ -10.3.floor()
-11

$ - 10.3.floor()
-10
```
@odino odino closed this as completed Jul 28, 2020
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

2 participants