<commit_before># This adds some extensions to BigDecimal for (limited) compatibility with BigFloat types

# require 'bigdecimal'

class BigDecimal

  class <<self
    def build(sign, coeff, exp)
      BigDecimal.new("#{sign*coeff}E#{exp}")
    end

    def Num(*args)
      if args.size==3
        build *args
      elsif args.size==2
        build +1, *args
      elsif args.size==1
        arg = args.first
        case arg
        when Rational
          BigDecimal.new(arg.numerator.to_s)/BigDecimal.new(arg.denominator.to_s)
        else
          BigDecimal.new(arg.to_s)
        end
      else
        raise ArgumentError, "wrong number of arguments (#{args.size} for 1, 2 or 3)"
      end
    end

    def radix
      10
    end

    # This provides an common interface (with BigFloat classes) to radix, etc.
    def context
      self
    end

  end

  def ulp(mode=:low)
    if self.nan?
      return self
    elsif self.infinite?
      return nil
    elsif self.zero?
      return nil
    else
      if BigDecimal.limit != 0
        prec = BigDecimal.limit
      else
        prec = [self.precs[0], Float::DIG].max
      end
      exp = self.exponent - (prec-1)
      BigDecimal.new "1E#{exp}"
    end
  end

end<commit_msg>Add BigDecimal::Math to simplify use of BigDecimal math functions.<commit_after># This adds some extensions to BigDecimal for (limited) compatibility with BigFloat types

require 'bigdecimal'
require 'bigdecimal/math'

class BigDecimal

  class <<self
    def build(sign, coeff, exp)
      BigDecimal.new("#{sign*coeff}E#{exp}")
    end

    def Num(*args)
      if args.size==3
        build *args
      elsif args.size==2
        build +1, *args
      elsif args.size==1
        arg = args.first
        case arg
        when Rational
          BigDecimal.new(arg.numerator.to_s)/BigDecimal.new(arg.denominator.to_s)
        else
          BigDecimal.new(arg.to_s)
        end
      else
        raise ArgumentError, "wrong number of arguments (#{args.size} for 1, 2 or 3)"
      end
    end

    def radix
      10
    end

    # This provides an common interface (with BigFloat classes) to radix, etc.
    def context
      self
    end

  end

  def ulp(mode=:low)
    if self.nan?
      return self
    elsif self.infinite?
      return nil
    elsif self.zero?
      return nil
    else
      if BigDecimal.limit != 0
        prec = BigDecimal.limit
      else
        prec = [self.precs[0], Float::DIG].max
      end
      exp = self.exponent - (prec-1)
      BigDecimal.new "1E#{exp}"
    end
  end

  module Math
    extend BigMath
  end

end
{'fraction_non_alphanumeric': 0.0885195206803247, 'fraction_numerical': 0.010050251256281407, 'mean_word_length': 1.9953703703703705, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '1044843', 'n_tokens_mistral': 839, 'n_tokens_neox': 818, 'n_words': 246}