Code Monkey home page Code Monkey logo

Comments (1)

olimaticer avatar olimaticer commented on July 17, 2024
	private boolean executeMF_INT() {					// 2014-03-16 gt
		if (!evalNumericExpression()) return false;
		Double iD = EvalNumericExpressionValue;
		if (!iD.isNaN() && !iD.isInfinite()){ //2018-01-15gt
			EvalNumericExpressionIntValue = EvalNumericExpressionValue.longValue();
			EvalNumericExpressionValue = Double.valueOf(EvalNumericExpressionIntValue);
		}//2018-01-15gt
		VarIsInt = true;
		return true;
	}
		private boolean executeMF_FRAC() { // 2014-03-16 gt
			if (!evalNumericExpression())
				return false;
			//Old version does not work correctly with big numbers like 4.5678879E8
			String str = EvalNumericExpressionValue.toString();
			Double iD = EvalNumericExpressionValue;
			if (!iD.isNaN() && !iD.isInfinite()){ //2018-01-15gt
				if (str.indexOf("E") > -1) {//vv2017-04-15gt
					str = new BigDecimal(EvalNumericExpressionValue).toPlainString();//2017-05-05gt
					//str = String.format(Locale.US,"%.18f", new BigDecimal(EvalNumericExpressionValue));
				} //^^2017-04-15gt
				String sgn = (EvalNumericExpressionValue < 0) ? "-" : "";
				int point = str.indexOf('.');
				EvalNumericExpressionValue = (point < 0) ? 0.0
						: Double.parseDouble(sgn + str.substring(point));
			} //2018-01-15gt
			return true;
		}
	private boolean executeMF_base(int base) {			// BIN, OCT, or HEX, depending on the base parameter
		if (!getStringArg()) return false;				// Get and check the string expression
		if (base == 2){//BIN()//vv2018-01-15gt
			if (StringConstant.equals("111111111111000000000000000000000000000000000000000000000000000")){//IEEE 754, "NaN";
				EvalNumericExpressionValue = Math.sqrt(-1);
				return true;
			}
			if (StringConstant.equals("111111111110000000000000000000000000000000000000000000000000000")){//IEEE 754, +Infinitive
				EvalNumericExpressionValue = 1.0/0;
				return true;
			}
			if (StringConstant.equals("1111111111110000000000000000000000000000000000000000000000000000")){ //IEEE 754, -Infinitive
				EvalNumericExpressionValue = -1.0/0;
				return true;
			}
		}
		if (base == 8){//OCT()
			if (StringConstant.equals("777700000000000000000")){//IEEE 754, "NaN";
				EvalNumericExpressionValue = Math.sqrt(-1);
				return true;
			}
			if (StringConstant.equals("777600000000000000000")){//IEEE 754, +Infinitive
				EvalNumericExpressionValue = 1.0/0;
				return true;
			}
			if (StringConstant.equals("1777600000000000000000")){ //IEEE 754, -Infinitive
				EvalNumericExpressionValue = -1.0/0;
				return true;
			}
		}
		if (base == 16){//HEX()
			if (StringConstant.equals("7ff8000000000000")){//IEEE 754, "NaN";
				EvalNumericExpressionValue = Math.sqrt(-1);
				return true;
			}
			if (StringConstant.equals("7ff0000000000000")){//IEEE 754, +Infinitive
				EvalNumericExpressionValue = 1.0/0;
				return true;
			}
			if (StringConstant.equals("fff0000000000000")){ //IEEE 754, -Infinitive
				EvalNumericExpressionValue = -1.0/0;
				return true;
			}
		}//^^2018-01-15gt
		try {
			EvalNumericExpressionIntValue = new BigInteger(StringConstant, base).longValue();
			EvalNumericExpressionValue = EvalNumericExpressionIntValue.doubleValue();
			VarIsInt = true;
		} catch (NumberFormatException e) {
			return RunTimeError("Not a valid number: " + StringConstant);
		}
		return true;
	}

	private boolean executeSF_INT() {													// INT$
		if (!evalNumericExpression())	return false;
		if (!isNext(')'))				return false;	// Function must end with ')'
		Double testIsN = EvalNumericExpressionValue;//vv2018-01-15gt
		if (testIsN.isNaN()){ 
			StringConstant = "NaN";
		}else if (testIsN.isInfinite()){ 
			StringConstant = "Infinity";
			if (testIsN < 0)StringConstant = "-Infinity";
		}else{ //^^2018-01-15gt
			long val = EvalNumericExpressionValue.longValue();
			StringConstant = Long.toString(val);
		} //2018-01-15gt
		return true;
	}

	private boolean executeSF_HEX() {													// HEX$
		if (!evalNumericExpression())	return false;
		if (!isNext(')'))				return false;	// Function must end with ')'
		Double testIsN = EvalNumericExpressionValue; //vv2018-01-15gt
		if (testIsN.isNaN()){
			StringConstant = "7ff8000000000000"; //IEEE 754, "NaN";
		}else if (testIsN.isInfinite()){ 
			StringConstant = "7ff0000000000000"; //IEEE 754, +Infinitive
			if (testIsN < 0)StringConstant = "fff0000000000000"; //IEEE 754, -Infinitive
		}else{ //^^2018-01-15gt
			long val = EvalNumericExpressionValue.longValue();
			StringConstant = Long.toHexString(val);
		} //2018-01-15gt
		return true;
	}

	private boolean executeSF_OCT() {													// OCT$
		if (!evalNumericExpression())	return false;
		if (!isNext(')'))				return false;	// Function must end with ')'
		Double testIsN = EvalNumericExpressionValue; //vv2018-01-15gt
		if (testIsN.isNaN()){
			StringConstant = "777700000000000000000"; //IEEE 754, "NaN";
		}else if (testIsN.isInfinite()){ 
			StringConstant = "777600000000000000000"; //IEEE 754, +Infinitive
			if (testIsN < 0)StringConstant = "1777600000000000000000"; //IEEE 754, -Infinitive
		}else{ //^^2018-01-15gt
			long val = EvalNumericExpressionValue.longValue();
		StringConstant = Long.toOctalString(val);
	} //2018-01-15gt
		return true;
	}

	private boolean executeSF_BIN() {													// BIN$
		if (!evalNumericExpression())	return false;
		if (!isNext(')'))				return false;	// Function must end with ')'
		Double testIsN = EvalNumericExpressionValue; //vv2018-01-15gt
		if (testIsN.isNaN()){
			StringConstant = "111111111111000000000000000000000000000000000000000000000000000"; //IEEE 754, "NaN";
		}else if (testIsN.isInfinite()){ 
			StringConstant = "111111111110000000000000000000000000000000000000000000000000000"; //IEEE 754, +Infinitive
			if (testIsN < 0)StringConstant = "1111111111110000000000000000000000000000000000000000000000000000"; //IEEE 754, -Infinitive
		}else{ //^^2018-01-15gt
			long val = EvalNumericExpressionValue.longValue();
		StringConstant = Long.toBinaryString(val);
	} //2018-01-15gt
		return true;
	}

Also supported IEEE 754, Infinitive now.
Gregor

from basic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.