Perl 5中是否定义了带有负操作数的%的行为? [英] Is the behavior of % with negative operands defined in Perl 5?

查看:58
本文介绍了Perl 5中是否定义了带有负操作数的%的行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直到最近(即C99),模运算符的行为都是用C定义的实现.由于Perl 5是用C编写的,它是否依赖于用于构建它的C编译器的行为?

Until recently (i.e. C99), the behavior of the modulo operator was implementation defined in C. Since Perl 5 is written in C, is it reliant on the behavior of the C compiler used to build it?

推荐答案

不,Perl 5在 perlop ,甚至进行了测试以确保其工作如文档所述.

No, Perl 5 defines the modulo operator in perlop and even has tests to ensure it works as documented.

来自perl/t/op/arith.t

from perl/t/op/arith.t

tryeq $T++,  13 %  4, 1;
tryeq $T++, -13 %  4, 3;
tryeq $T++,  13 % -4, -3;
tryeq $T++, -13 % -4, -1;

但是,如果您使用 integer 编译指示,您将受到C编译器.

However, if you use the integer pragma, you are at the mercies of the C compiler.

这篇关于Perl 5中是否定义了带有负操作数的%的行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆