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

Re: strange behavior of modulus operator #120

Closed
p5pRT opened this issue Jun 27, 1999 · 2 comments
Closed

Re: strange behavior of modulus operator #120

p5pRT opened this issue Jun 27, 1999 · 2 comments

Comments

@p5pRT
Copy link

@p5pRT p5pRT commented Jun 27, 1999

Migrated from rt.perl.org#924 (status was 'resolved')

Searchable as RT924$

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jun 27, 1999

From @gsar

This is important.

modulus operator as implemented by your C compiler\.  This
operator is not as well defined for negative operands\, but
it will execute faster\.

I don't know if the technical description correctly describes what
perl is doing, but it says that it should "give you direct access to
the modulus operator as implemented by your C compiler." On both my
Sun WorkShop Compilers 4.2 (SunOS5.6) and my gcc version egcs-2.91.66
(SunOS5.7) give

-1 % 2 = -1

while perl gives me

-1 % 2 = 1

Doesn't too. Perl knows both ways to skin a modulus, depending on
whether C<use integer> is in scope. Try it.

Sarathy
gsar@​activestate.com

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Mar 28, 2000

From [Unknown Contact. See original ticket]

On Tue, 14 Mar 2000 19​:27​:51 MST, Tom Christiansen wrote​:

DB<1> use POSIX

DB<2> O UsageOnly
UsageOnly = '1'
DB<3> V POSIX
Not a GLOB reference at lib/dumpvar.pl line 408, <IN> line 3.

Looks like dumpvar doesn't know about these funny bits​:

% perl -lwe 'sub foo; print $main​::{foo}'
-1
% perl -lwe 'sub foo ($@​); print $main​::{foo}'
$@​

Is this particularly useful? It seems fragile. One mention of
the typeglob without sneaking around Perl's back, and those
properties are gone.

% perl -lwe 'sub foo ($@​); print $​::{foo}; print *foo; print $​::{foo}'
*main​::foo
*main​::foo
*main​::foo

If you disguise your intent from the compiler, you get by... once.

% perl -lwe 'sub foo; print $main​::{foo}; eval q{print *foo}; print $main​::{foo}'
-1
*main​::foo
*main​::foo

% perl -lwe 'sub foo ($@​); print $main​::{foo}; eval q{print *foo}; print $main​::{foo}'
$@​
*main​::foo
*main​::foo

And of course, no difference here​:

% perl -lwe 'sub foo ($@​); print $​::{foo}; eval q{print *foo}; print $​::{foo}'
$@​
*main​::foo
*main​::foo

Hm... I wonder whether the compiler could ever look into single-quoted,
compiled-time resolved strings on its eval q{...} stuff to learn more
about what's afoot?

--tom

@p5pRT p5pRT closed this Nov 28, 2003
toddr pushed a commit that referenced this issue Oct 19, 2019
Optional flags arg to disable bless|tie on retrieve/thaw

Signed-off-by: Reini Urban <rurban@cpanel.net>
and added documentation, reformat, compute CAN_FLOCK at compile-time.
See [cperl #120]

TonyC:

 - removed pod/perlcdelta.pod changes
 - this commit removed auto-loading modules for overloading, which
   was reinstated in a later commit.

cherry-picked from 04b58ce
toddr pushed a commit that referenced this issue Oct 19, 2019
Optional flags arg to disable bless|tie on retrieve/thaw

Signed-off-by: Reini Urban <rurban@cpanel.net>
and added documentation, reformat, compute CAN_FLOCK at compile-time.
See [cperl #120]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant