Skip to content

Commit

Permalink
Change default setting of $Math::GMPq::RETYPE from 0 to 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphus committed Jul 6, 2024
1 parent c090f02 commit 0950eb5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Revision history for Perl module Math::GMPq

0.57
- Silence pointless compiler warnings.
- Change initial setting of Math::GMPq::RETYPE from 0 to 1.

0.56
- Skip Math::MPFR checks in t/overload_cross_class.t and t/overload_op_eq.t if
Expand Down
8 changes: 5 additions & 3 deletions GMPq.pm
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@ qgmp_urandomb_ui qgmp_urandomm_ui

sub dl_load_flags {0} # Prevent DynaLoader from complaining and croaking

$Math::GMPq::RETYPE = 0; # set to 1 to enable a Math::GMPq object to be coerced to
$Math::GMPq::RETYPE = 1; # This variable used to be initially set to 0, but
# this has changed, beginning with Math::GMPq-0.57.
# This enables a Math::GMPq object to be coerced to
# a Math::MPFR object in certain overloaded operations.
# (See the 'OPERATOR OVERLOADING' section of the POD
# documentation for details.)
# With this variable set to 0, these "certain overloaded
# operations" alluded to will throw a fatal error.
# Setting this variable to 0 will cause these "certain
# overloaded operations" to throw a fatal error.

sub new {

Expand Down
14 changes: 7 additions & 7 deletions GMPq.pod
Original file line number Diff line number Diff line change
Expand Up @@ -548,13 +548,13 @@
Math::MPFR objects can provided as the second arg with '+', '-',
'*', '/' and '**' operators - in which case the operation will
return a Math::MPFR object.
If $Math::GMPq::RETYPE is set to 1, then Math::MPFR objects can also
be provided as the second arg with '+=', '*=', '-=', '/=' and '**='
operators. In such instances, the Math::GMPq object becomes
(is "retyped" to) a Math::MPFR object that contains the result of
the operation, using default Math::MPFR precision and default
Math::MPFR rounding mode.
$Math::GMPq::RETYPE is initially set to 0 (false).
If $Math::GMPq::RETYPE is set to 1 (as is the default setting), then
Math::MPFR objects can also be provided as the second arg with
'+=', '*=', '-=', '/=' and '**=' operators. In such instances,
the Math::GMPq object becomes (is "retyped" to) a Math::MPFR object
that contains the result of the operation, using default Math::MPFR
precision and default Math::MPFR rounding mode.
Set $Math::GMPq::RETYPE to 0, to disable this capability.

To determine the type and value of the second argument the subroutine
works through the following steps (in order), using the first value
Expand Down
7 changes: 5 additions & 2 deletions t/overload_op_eq.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
# to a true value.
# A fatal error occurs if $Math::GMPq::RETYPE is
# set to a false value. The initial value of
# $Math::GMPq::RETYPE is 0 (false).
# $Math::GMPq::RETYPE is now 1 (true), but was 0
# in Math-GMPq-0.56 and earlier.

use strict;
use warnings;
Expand All @@ -22,7 +23,9 @@ my $q = Math::GMPq->new('1/11');
my $fr = 0;
$fr = Math::MPFR->new(17.1) if $have_mpfr;

cmp_ok($Math::GMPq::RETYPE, '==', 0, "retyping not allowed");
cmp_ok($Math::GMPq::RETYPE, '==', 1, "retyping allowed");

$Math::GMPq::RETYPE = 0; # Disallow retyping

eval {$q *= $fr;};
if(ref($fr)) {
Expand Down

0 comments on commit 0950eb5

Please sign in to comment.