The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
Changes 011
Int64.xs 23
META.json 22
META.yml 22
c_api.h 22
c_api_client/perl_math_int64.c 22
c_api_client/perl_math_int64.h 311
lib/Math/Int64.pm 211
t/Math-Int64.t 310
t/Math-UInt64.t 210
templates/module_h.temp 19
11 files changed (This is a version diff) 2173
@@ -1,5 +1,16 @@
 Revision history for Perl extension Math::Int64.
 
+0.34  Oct 30, 2014
+        - native_to_uint64 was broken when using native integers (bug
+          report by Aleksey Mashanov)
+        - add sv_seti64 and sv_setu64 macros (feature request by
+          Graham Ollis)
+
+0.33  Oct 28, 2014
+        - fix test failures caused by operator ** sometimes not being
+          precise enough (reported by John David Anglin, Gregor
+          Herrmann and Sisyphus)
+
 0.32  Sep 9, 2014
         - BER_length was broken (bug report and solution by Mark Donovan)
         - add native U64 to NV conversion support for some versions of MS
@@ -803,8 +803,9 @@ CODE:
     if (len != 8)
         croak_string(aTHX_ invalid_length_error_u);
     if (use_native) {
-        RETVAL = newSVuv(0);
-        Copy(pv, &(SvUVX(RETVAL)), 8, char);
+        uint64_t tmp;
+        Copy(pv, &tmp, 8, char);
+        RETVAL = newSVuv(tmp);
     }
     else {
         RETVAL = newSVu64(aTHX_ 0);
@@ -4,7 +4,7 @@
       "Salvador Fandino <sfandino@yahoo.com>"
    ],
    "dynamic_config" : 1,
-   "generated_by" : "ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.140640",
+   "generated_by" : "ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.142060",
    "license" : [
       "unknown"
    ],
@@ -40,5 +40,5 @@
          "url" : "https://github.com/salva/p5-Math-Int64"
       }
    },
-   "version" : "0.32"
+   "version" : "0.34"
 }
@@ -7,7 +7,7 @@ build_requires:
 configure_requires:
   ExtUtils::MakeMaker: '0'
 dynamic_config: 1
-generated_by: 'ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.140640'
+generated_by: 'ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.142060'
 license: unknown
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -20,4 +20,4 @@ no_index:
 requires: {}
 resources:
   repository: https://github.com/salva/p5-Math-Int64
-version: '0.32'
+version: '0.34'
@@ -2,8 +2,8 @@
  * c_api.h - This file is in the public domain
  * Author: Salvador Fandino <sfandino@yahoo.com>
  *
- * Generated on: 2012-09-03 13:11:15
- * Math::Int64 version: 0.27_04
+ * Generated on: 2014-10-30 11:43:56
+ * Math::Int64 version: 0.33
  * Module::CAPIMaker version: 0.02
  */
 
@@ -2,8 +2,8 @@
  * perl_math_int64.c - This file is in the public domain
  * Author: Salvador Fandino <sfandino@yahoo.com>
  *
- * Generated on: 2012-09-03 13:11:15
- * Math::Int64 version: 0.27_04
+ * Generated on: 2014-10-30 11:43:56
+ * Math::Int64 version: 0.33
  * Module::CAPIMaker version: 0.02
  */
 
@@ -1,10 +1,10 @@
 /*
  * perl_math_int64.h - This file is in the public domain
  * Author: Salvador Fandino <sfandino@yahoo.com>
- * Version: 2.0
+ * Version: 2.1
  *
- * Generated on: 2012-09-03 13:11:15
- * Math::Int64 version: 0.27_04
+ * Generated on: 2014-10-30 11:43:56
+ * Math::Int64 version: 0.33
  * Module::CAPIMaker version: 0.02
  */
 
@@ -54,6 +54,14 @@ extern uint64_t  (*math_int64_c_api_randU64)(pTHX);
 #undef newSVu64
 #define newSVu64 newSVuv
 
+#define sv_seti64 sv_setiv_mg
+#define sv_setu64 sv_setuv_mg
+
+#else
+
+#define sv_seti64(target, i64) (sv_setsv_mg(target, sv_2mortal(newSVi64(i64))))
+#define sv_setu64(target, u64) (sv_setsv_mg(target, sv_2mortal(newSVu64(u64))))
+
 #endif
 
 #endif
\ No newline at end of file
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 
 BEGIN {
-    our $VERSION = '0.32';
+    our $VERSION = '0.34';
 
     require XSLoader;
     XSLoader::load('Math::Int64', $VERSION);
@@ -382,7 +382,8 @@ identical.
 
 Perl is prone to coerce integers into floats while this module keeps
 then always as 64bit integers. Specifically, the division operation
-and overflows are the most problematic cases.
+and overflows are the most problematic cases. Also, when using native
+integers, the signed/unsigned division blurs.
 
 Besides that, in most situations it is safe to use the native fallback.
 
@@ -513,6 +514,14 @@ Returns true is the given SV contains a valid uint64_t value.
 
 Returns a random 64 bits unsigned integer.
 
+=item SV sv_seti64(SV *sv, uint64_t i64)
+
+Sets the value of the perl scalar to the given int64_t value.
+
+=item SV sv_setu64(SV *sv, uint64_t i64)
+
+Sets the value of the perl scalar to the given uint64_t value.
+
 =back
 
 If you require any other function available through the C API don't
@@ -153,6 +153,14 @@ for ( int64('1271310319617'),
     is($ber_length, BER_length($ber . pack ("C*", map rand(256), 0..rand(10))));
 }
 
+# pow (**) precision sometimes is not good enough!
+sub ipow {
+    my ($base, $exp) = @_;
+    my $r = 1;
+    $r *= $base for (1..$exp);
+    $r;
+}
+
 my $two  = int64(2);
 my $four = int64(4);
 is ($two  ** -1, 0, "signed pow 2**-1");
@@ -172,12 +180,11 @@ for my $j (0..63) {
     next unless $j;
 
     my $max = (((int64(2)**62)-1)*2)+1;
-    is($max >> $j, $max / ( 2**$j ), "max int64 >> $j");
+    is($max >> $j, $max / ipow(2, $j), "max int64 >> $j");
 
     my $copy = int64($max);
     $copy >>= $j;
-    is($copy, $max / ( 2**$j ), "max int64 >>= $j");
-
+    is($copy, $max / ipow(2, $j), "max int64 >>= $j");
 }
 
 done_testing();
@@ -146,6 +146,14 @@ for (1..50) {
     is("$n", BER_to_uint64(uint64_to_BER($n)));
 }
 
+# pow (**) precision sometimes is not good enough!
+sub ipow {
+    my ($base, $exp) = @_;
+    my $r = 1;
+    $r *= $base for (1..$exp);
+    $r;
+}
+
 my $two  = uint64(2);
 my $four = uint64(4);
 is ($two  ** -1, 0, "signed pow 2**-1");
@@ -165,11 +173,11 @@ for my $j (0..63) {
     next unless $j;
 
     my $max = (((uint64(2)**63)-1)*2)+1;
-    is($max >> $j, $max / ( 2**$j ), "max uint64 >> $j");
+    is($max >> $j, $max / ipow(2, $j), "max uint64 >> $j");
 
     my $copy = uint64($max);
     $copy >>= $j;
-    is($copy, $max / ( 2**$j ), "max uint64 >>= $j");
+    is($copy, $max / ipow(2, $j), "max uint64 >>= $j");
 }
 
 
@@ -1,7 +1,7 @@
 /*
  * <% $module_h_filename %> - This file is in the public domain
  * Author: <% $author %>
- * Version: 2.0
+ * Version: 2.1
  *
  * Generated on: <% $now %>
  * <% $module_name %> version: <% $module_version %>
@@ -52,6 +52,14 @@ extern int math_int64_c_api_max_version;
 #undef newSVu64
 #define newSVu64 newSVuv
 
+#define sv_seti64 sv_setiv_mg
+#define sv_setu64 sv_setuv_mg
+
+#else
+
+#define sv_seti64(target, i64) (sv_setsv_mg(target, sv_2mortal(newSVi64(i64))))
+#define sv_setu64(target, u64) (sv_setsv_mg(target, sv_2mortal(newSVu64(u64))))
+
 #endif
 
 #endif
\ No newline at end of file