<commit_before>use 5.014;
use warnings;

our ($ROUND, $PREC);

#
## MPFR
#

Class::Multimethods::multimethod __log__ => qw(Math::MPFR) => sub {
    my ($x) = @_;

    # Complex for x < 0
    if (Math::MPFR::Rmpfr_sgn($x) < 0) {
        (@_) = _mpfr2mpc($_[0]);
        goto &__log__;
    }

    Math::MPFR::Rmpfr_log($x, $x, $ROUND);
    $x;
};

Class::Multimethods::multimethod __log2__ => qw(Math::MPFR) => sub {
    my ($x) = @_;

    # Complex for x < 0
    if (Math::MPFR::Rmpfr_sgn($x) < 0) {
        (@_) = _mpfr2mpc($_[0]);
        goto &__log2__;
    }

    Math::MPFR::Rmpfr_log2($x, $x, $ROUND);
    $x;
};

Class::Multimethods::multimethod __log10__ => qw(Math::MPFR) => sub {
    my ($x) = @_;

    # Complex for x < 0
    if (Math::MPFR::Rmpfr_sgn($x) < 0) {
        (@_) = _mpfr2mpc($_[0]);
        goto &__log10__;
    }

    Math::MPFR::Rmpfr_log10($x, $x, $ROUND);
    $x;
};

#
## MPC
#

Class::Multimethods::multimethod __log__ => qw(Math::MPC) => sub {
    my ($x) = @_;
    Math::MPC::Rmpc_log($x, $x, $ROUND);
    $x;
};

Class::Multimethods::multimethod __log2__ => qw(Math::MPC) => sub {
    my ($x) = @_;
    my $ln2 = Math::MPFR::Rmpfr_init2($PREC);
    Math::MPFR::Rmpfr_const_log2($ln2, $ROUND);
    Math::MPC::Rmpc_log($x, $x, $ROUND);
    Math::MPC::Rmpc_div_fr($x, $x, $ln2, $ROUND);
    $x;
};

Class::Multimethods::multimethod __log10__ => qw(Math::MPC) => sub {
    my ($x) = @_;
    Math::MPC::Rmpc_log10($x, $x, $ROUND);
    $x;
};

1;<commit_msg>- Workaround for Math::MPC::Rmpc_log10() with version of MPC < 1.0.0. (https://github.com/trizen/Math-AnyNum/issues/1)<commit_after>use 5.014;
use warnings;

our ($ROUND, $PREC);

#
## MPFR
#

Class::Multimethods::multimethod __log__ => qw(Math::MPFR) => sub {
    my ($x) = @_;

    # Complex for x < 0
    if (Math::MPFR::Rmpfr_sgn($x) < 0) {
        (@_) = _mpfr2mpc($_[0]);
        goto &__log__;
    }

    Math::MPFR::Rmpfr_log($x, $x, $ROUND);
    $x;
};

Class::Multimethods::multimethod __log2__ => qw(Math::MPFR) => sub {
    my ($x) = @_;

    # Complex for x < 0
    if (Math::MPFR::Rmpfr_sgn($x) < 0) {
        (@_) = _mpfr2mpc($_[0]);
        goto &__log2__;
    }

    Math::MPFR::Rmpfr_log2($x, $x, $ROUND);
    $x;
};

Class::Multimethods::multimethod __log10__ => qw(Math::MPFR) => sub {
    my ($x) = @_;

    # Complex for x < 0
    if (Math::MPFR::Rmpfr_sgn($x) < 0) {
        (@_) = _mpfr2mpc($_[0]);
        goto &__log10__;
    }

    Math::MPFR::Rmpfr_log10($x, $x, $ROUND);
    $x;
};

#
## MPC
#

Class::Multimethods::multimethod __log__ => qw(Math::MPC) => sub {
    my ($x) = @_;
    Math::MPC::Rmpc_log($x, $x, $ROUND);
    $x;
};

Class::Multimethods::multimethod __log2__ => qw(Math::MPC) => sub {
    my ($x) = @_;
    my $ln2 = Math::MPFR::Rmpfr_init2($PREC);
    Math::MPFR::Rmpfr_const_log2($ln2, $ROUND);
    Math::MPC::Rmpc_log($x, $x, $ROUND);
    Math::MPC::Rmpc_div_fr($x, $x, $ln2, $ROUND);
    $x;
};

Class::Multimethods::multimethod __log10__ => qw(Math::MPC) => sub {
    my ($x) = @_;

    state $MPC_VERSION = Math::MPC::MPC_VERSION();

    if ($MPC_VERSION >= 65536) {    # available only in mpc>=1.0.0
        Math::MPC::Rmpc_log10($x, $x, $ROUND);
    }
    else {
        my $ln10 = Math::MPFR::Rmpfr_init2($PREC);
        Math::MPFR::Rmpfr_set_ui($ln10, 10, $ROUND);
        Math::MPFR::Rmpfr_log($ln10, $ln10, $ROUND);
        Math::MPC::Rmpc_log($x, $x, $ROUND);
        Math::MPC::Rmpc_div_fr($x, $x, $ln10, $ROUND);
    }

    $x;
};

1;
{'fraction_non_alphanumeric': 0.22714203565267396, 'fraction_numerical': 0.028464634847613572, 'mean_word_length': 3.1220379146919433, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 29, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6777413', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1598, 'n_words': 253}