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

% doesn't clamp_nonzero when divisor is decimal #493

Closed
yzhang90 opened this issue Nov 23, 2017 · 1 comment
Closed

% doesn't clamp_nonzero when divisor is decimal #493

yzhang90 opened this issue Nov 23, 2017 · 1 comment

Comments

@yzhang90
Copy link

What's your issue about?

viper code:
p = x % 0.0 is compile into [smod, [mul, [mload, 320 <x>], 10000000000], 0]
without checking whether the divisor is zero.

How can it be fixed?

in expr.py:

def arithmetic(self):
    ...
    elif isinstance(self.expr.op, ast.Mod):
        ...
        elif ltyp == 'num' and rtyp == 'decimal':
            o = LLLnode.from_list(['smod', ['mul', left, DECIMAL_DIVISOR], ['clamp_nonzero', right]],
                                  typ=BaseType('decimal', new_unit), pos=getpos(self.expr))

Cute Animal Picture

holgs2x

@fubuloubu
Copy link
Member

Good catch, that is definitely a problem!

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