subAndAss method

MathFract subAndAss(
  1. dynamic r
)

Implementation

MathFract subAndAss( dynamic r ){
	if( r is MathFract ){
		if( _mi != r._mi ){
			// this += -r
			addAndAss( r.minus() );
		} else if( _de == 0 ){
		} else if( r._de == 0 ){
			ass( r );
		} else {
			double de = ClipMath.lcm( _de, r._de );
			double nu = _nu * de / _de - r._nu * de / r._de;
			if( nu < 0.0 ){
				_mi = _mi ? false : true;
				_set( -nu, de );
			} else {
				_set( nu, de );
			}
		}
	} else {
		double rr = ClipMath.toDouble(r);
		if( _mi != (rr < 0.0) ){
			// this += -rr
			addAndAss( -rr );
		} else {
			double t = (rr < 0.0) ? -rr : rr;
			if( t == ClipMath.toInt( t ) ){
				double nu = _nu - t * _de;
				if( nu < 0.0 ){
					_mi = _mi ? false : true;
					_set( -nu, _de );
				} else {
					_set( nu, _de );
				}
			} else {
				subAndAss( floatToFract( rr ) );
			}
		}
	}
	return this;
}