<commit_before>// Copyright 2017, University of Colorado Boulder

/**
 * A key accumulator that collects user input for integer and floating point values, intended for use in conjunction
 * with the common-code keypad.
 *
 * @author <NAME>
 * @author <NAME>
 * @author <NAME> (PixelZoom, Inc.)
 */
define( function( require ) {
  'use strict';

  // modules
  var AbstractKeyAccumulator = require( 'SCENERY_PHET/keypad/AbstractKeyAccumulator' );
  var DerivedProperty = require( 'AXON/DerivedProperty' );
  var inherit = require( 'PHET_CORE/inherit' );
  var KeyID = require( 'SCENERY_PHET/keypad/KeyID' );
  var sceneryPhet = require( 'SCENERY_PHET/sceneryPhet' );
  var Tandem = require( 'TANDEM/Tandem' );

  // constants
  var NEGATIVE_CHAR = '\u2212';
  var DECIMAL_CHAR = '.';
  var MAX_SAFE_INTEGER = 9007199254740991; // Used as references for various `Number` constants

  /**
   * @param {Object} [options]
   * @constructor
   */
  function NumberAccumulator( options ) {
    Tandem.indicateUninstrumentedCode();

    var self = this;
    options = _.extend( {
      maxDigitsRightOfMantissa: 0,
      maxDigits: MAX_SAFE_INTEGER.toString().length
    }, options );

    AbstractKeyAccumulator.call( this, options );

    this.maxDigitsRightOfMantissa = options.maxDigitsRightOfMantissa; // @private
    this.maxDigits = options.maxDigits; // @private

    // @public (read-only) - string representation of the keys entered by the user
    this.stringProperty = new DerivedProperty( [ this.accumulatedKeysProperty ], function( accumulatedKeys ) {
      return self.keysToString( accumulatedKeys );
    } );

    // @public (read-only) - numerical value of the keys entered by the user
    this.valueProperty = new DerivedProperty( [ this.stringProperty ], function( stringValue ) {
      return self.stringToInteger( stringValue );
    } );
  }

  sceneryPhet.register( 'NumberAccumulator', NumberAccumulator );

  return inherit( AbstractKeyAccumulator, NumberAccumulator, {

    /**
     * invoked when a key is pressed and creates proposed set of keys to be passed to the validator
     * @param {KeyID} keyIdentifier - identifier for the key pressed
     * @public
     * @override
     */
    handleKeyPressed: function( keyIdentifier ) {
      var newArray = this.handleClearOnNextKeyPress( keyIdentifier );<commit_msg>modified the handling of maxDigits, see #332<commit_after>// Copyright 2017, University of Colorado Boulder

/**
 * A key accumulator that collects user input for integer and floating point values, intended for use in conjunction
 * with the common-code keypad.
 *
 * @author <NAME>
 * @author <NAME>
 * @author <NAME> (PixelZoom, Inc.)
 */
define( function( require ) {
  'use strict';

  // modules
  var AbstractKeyAccumulator = require( 'SCENERY_PHET/keypad/AbstractKeyAccumulator' );
  var DerivedProperty = require( 'AXON/DerivedProperty' );
  var inherit = require( 'PHET_CORE/inherit' );
  var KeyID = require( 'SCENERY_PHET/keypad/KeyID' );
  var sceneryPhet = require( 'SCENERY_PHET/sceneryPhet' );
  var Tandem = require( 'TANDEM/Tandem' );

  // constants
  var NEGATIVE_CHAR = '\u2212';
  var DECIMAL_CHAR = '.';

  // Define the maximum integer that can be handled.  The portion with the explicit numeric value is necessary for IE11
  // support, see https://github.com/phetsims/scenery-phet/issues/332.
  var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
  var MAX_DIGITS = MAX_SAFE_INTEGER.toString().length - 1;

  /**
   * @param {Object} [options]
   * @constructor
   */
  function NumberAccumulator( options ) {
    Tandem.indicateUninstrumentedCode();

    var self = this;
    options = _.extend( {
      maxDigitsRightOfMantissa: 0,
      maxDigits: MAX_DIGITS
    }, options );

    assert && assert(
      options.maxDigits > 0 && options.maxDigits <= MAX_DIGITS,
      'maxDigits out of range: ' + options.maxDigits
    );

    AbstractKeyAccumulator.call( this, options );

    this.maxDigitsRightOfMantissa = options.maxDigitsRightOfMantissa; // @private
    this.maxDigits = options.maxDigits; // @private

    // @public (read-only) - string representation of the keys entered by the user
    this.stringProperty = new DerivedProperty( [ this.accumulatedKeysProperty ], function( accumulatedKeys ) {
      return self.keysToString( accumulatedKeys );
    } );

    // @public (read-only) - numerical value of the keys entered by the user
    this.valueProperty = new DerivedProperty( [ this.stringProperty ], function( stringValue ) {
      return self.stringToInteger( stringValue );
    } );
  }

  sceneryPhet.register( 'NumberAccumulator', NumberAccumulator );

  return inherit( AbstractKeyAccumulator, NumberAccumulator, {

    /**
     * invoked when a key is pressed and creates proposed set of keys to be passed to the validator
     * @param {KeyID} keyIdentifier - identifier for the key pressed
     * @public
     * @override
     */
    handleKeyPressed: function( keyIdentifier ) {
      var newArray = this.handleClearOnNextKeyPress( keyIdentifier );
{'fraction_non_alphanumeric': 0.10413779449613937, 'fraction_numerical': 0.01187883587408434, 'mean_word_length': 3.5802357207615594, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '792986', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1510, 'n_words': 421}