<commit_before>import _ from 'lodash';
import NumberType from './Number';

/**
 * Calculate the max absolute value for the given precision and scale.
 * @param {number} precision the number of total digits in value, including decimals.
 * @param {number} [scale] the numver of decimal digits in value.
 * @return {number}
 * @private
 */
function calculateMaxValue(precision: number, scale: ?number): number {
  const arr = _.fill(Array(precision), '9');

  if (scale) {
    arr.splice(precision - scale, '.');
  }

  return parseFloat(arr.join(''));
}

class FloatType extends NumberType {

  constructor() {
    super();
  }

  set precision(v: number): void {
    this.props.precision = v;
  }

  set scale(v: number): void {
    this.props.scale = v;
  }

  toJoi(): Object {
    // reset max + min values based on precision + scale
    if (!_.isUndefined(this.props.precision)) {
      const maxValue = calculateMaxValue(this.props.precision, this.props.scale);

      if (_.isUndefined(this.props.max) || this.props.max > maxValue) {
        this.props.max = maxValue;
      }

      if (_.isUndefined(this.props.min) || this.props.min < -maxValue) {
        this.props.min = -maxValue;
      }
    }

    let joi = super.toJoi();

    if (this.props.scale) {
      joi = joi.precision(this.props.scale);
    }

    return joi;
  }

  toJSON(): Object {
    return _.chain(this.props)
      .clone()
      .assign({type: 'float'})
      .value();
  }

}

export default FloatType;
<commit_msg>Bugfix: missing argument in splice method<commit_after>import _ from 'lodash';
import NumberType from './Number';

/**
 * Calculate the max absolute value for the given precision and scale.
 * @param {number} precision the number of total digits in value, including decimals.
 * @param {number} [scale] the numver of decimal digits in value.
 * @return {number}
 * @private
 */
function calculateMaxValue(precision: number, scale: ?number): number {
  const arr = _.fill(Array(precision), '9');

  if (scale) {
    arr.splice(precision - scale, 0, '.');
  }

  return parseFloat(arr.join(''));
}

class FloatType extends NumberType {

  constructor() {
    super();
  }

  set precision(v: number): void {
    this.props.precision = v;
  }

  set scale(v: number): void {
    this.props.scale = v;
  }

  toJoi(): Object {
    // reset max + min values based on precision + scale
    if (!_.isUndefined(this.props.precision)) {
      const maxValue = calculateMaxValue(this.props.precision, this.props.scale);

      if (_.isUndefined(this.props.max) || this.props.max > maxValue) {
        this.props.max = maxValue;
      }

      if (_.isUndefined(this.props.min) || this.props.min < -maxValue) {
        this.props.min = -maxValue;
      }
    }

    let joi = super.toJoi();

    if (this.props.scale) {
      joi = joi.precision(this.props.scale);
    }

    return joi;
  }

  toJSON(): Object {
    return _.chain(this.props)
      .clone()
      .assign({type: 'float'})
      .value();
  }

}

export default FloatType;

{'fraction_non_alphanumeric': 0.14328161109276988, 'fraction_numerical': 0.0009904258831297458, 'mean_word_length': 2.811320754716981, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1035813', 'n_tokens_mistral': 1013, 'n_tokens_neox': 963, 'n_words': 256}