Skip to content
Snippets Groups Projects
Commit acf36e6d authored by gregor herrmann's avatar gregor herrmann
Browse files

[svn-inject] Installing original source of libdata-integer-perl

parents
No related merge requests found
Makefile Makefile.old
blib pm_to_blib
META.yml
Data-Integer-*
Changes 0 → 100644
version 0.001; 2007-01-24
* bugfix: strategic use of "use integer" to make the arithmetic work
right on perl 5.6
* reference Data::Float, Scalar::Number, and perlnumber(1) in
documentation
version 0.000; 2007-01-09
* initial released version
.cvsignore
Changes
MANIFEST
META.yml
Makefile.PL
README
lib/Data/Integer.pm
t/const.t
META.yml 0 → 100644
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: Data-Integer
version: 0.001
version_from: lib/Data/Integer.pm
installdirs: site
requires:
distribution_type: module
generated_by: ExtUtils::MakeMaker version 6.17
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => "Data::Integer",
VERSION_FROM => "lib/Data/Integer.pm",
PREREQ_PM => { },
);
README 0 → 100644
NAME
Data::Integer - details of the native integer data type
DESCRIPTION
This module is about the native integer numerical data type. A native
integer is one of the types of datum that can appear in the numeric part
of a Perl scalar. This module supplies constants describing the native
integer type.
There are actually two native integer representations: signed and
unsigned. Both are handled by this module.
INSTALLATION
perl Makefile.PL
make
make test
make install
AUTHOR
Andrew Main (Zefram) <zefram@fysh.org>
COPYRIGHT
Copyright (C) 2007 Andrew Main (Zefram) <zefram@fysh.org>
This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=head1 NAME
Data::Integer - details of the native integer data type
=head1 SYNOPSIS
use Data::Integer qw(max_natint);
$n = max_natint;
# and other constants; see text
=head1 DESCRIPTION
This module is about the native integer numerical data type. A native
integer is one of the types of datum that can appear in the numeric part
of a Perl scalar. This module supplies constants describing the native
integer type.
There are actually two native integer representations: signed and
unsigned. Both are handled by this module.
=cut
package Data::Integer;
use warnings;
use strict;
our $VERSION = "0.001";
use base "Exporter";
our @EXPORT_OK = qw(
natint_bits min_natint max_natint
min_signed_natint max_signed_natint
min_unsigned_natint max_unsigned_natint
);
=head1 CONSTANTS
=over
=item natint_bits
The width, in bits, of the native integer data type.
=item min_natint
The minimum representable value. This is -2^(natint_bits - 1).
=item max_natint
The maximum representable value. This is 2^natint_bits - 1.
=item min_signed_natint
The minimum representable value in the signed representation. This is
-2^(natint_bits - 1).
=item max_signed_natint
The maximum representable value in the signed representation. This is
2^(natint_bits - 1) - 1.
=item min_unsigned_natint
The minimum representable value in the unsigned representation.
This is zero.
=item max_unsigned_natint
The maximum representable value in the unsigned representation. This is
2^natint_bits - 1.
=back
=cut
# Count the number of bits in native integers by repeatedly shifting a bit
# left until it turns into the sign bit. "use integer" forces the use of a
# signed integer representation.
{
use integer;
my $natint_bits = 1;
my $min_signed_natint = 1;
while($min_signed_natint > 0) {
$natint_bits++;
$min_signed_natint <<= 1;
}
*natint_bits = sub () { $natint_bits };
*min_signed_natint = sub () { $min_signed_natint };
}
# The rest of the code is parsed after the constants above have been
# calculated and installed, so that it can benefit from their constancy.
eval do { local $/; <DATA>; } or die $@;
__DATA__
local $SIG{__DIE__};
use constant max_signed_natint => do { use integer; ~min_signed_natint };
use constant min_unsigned_natint => 0;
use constant max_unsigned_natint => max_signed_natint + max_signed_natint + 1;
*min_natint = \&min_signed_natint;
*max_natint = \&max_unsigned_natint;
=head1 SEE ALSO
L<Data::Float>,
L<Scalar::Number>,
L<perlnumber(1)>
=head1 AUTHOR
Andrew Main (Zefram) <zefram@fysh.org>
=head1 COPYRIGHT
Copyright (C) 2007 Andrew Main (Zefram) <zefram@fysh.org>
This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
1;
use Test::More tests => 10;
BEGIN { use_ok "Data::Integer", qw(
natint_bits min_natint max_natint
min_signed_natint max_signed_natint
min_unsigned_natint max_unsigned_natint
); }
ok int(natint_bits) == natint_bits;
ok natint_bits >= 16;
use integer;
my $a = -1;
for(my $i = natint_bits-1; $i--; ) { $a += $a; }
is $a, min_signed_natint;
is $a, min_natint;
is min_signed_natint + max_signed_natint, -1;
no integer;
is min_unsigned_natint, 0;
my $b = 1;
my $c = 1;
for(my $i = natint_bits-1; $i--; ) { $b += $b; $c += $b; }
is $b - 1, max_signed_natint;
is $c, max_unsigned_natint;
is $c, max_natint;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment