<commit_before>package com.RyanHodin.Calculator;

import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import java.math.BigInteger;

public class MainActivity extends Activity
{
	public double currentValue=0;

	/** Called when the activity is first created. */
	@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB)
		{
			getActionBar().hide();
			if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.ICE_CREAM_SANDWICH)
				findViewById(R.id.mainLayout).setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
		}
		setZero();
	}

	public double parseDouble(String num)
	{
		if (num.indexOf("Error", 0)==0 || num.indexOf("ERROR", 0)==0)
			return 0;
		if (num.charAt(num.length()-1)=='\u03C0')
		{
			if (num.length()==1)
				return Math.PI;
			else if (num.length()==2 && num.charAt(0)=='-') // If the string is two long and the first character is a negation
				return -Math.PI; // Return negative pi
			return parseDouble(num.substring(0, num.length()-1))*Math.PI;
		}
		if (num.charAt(num.length()-1)=='e')
		{
			if (num.length()==1)
				return Math.E;
			else if (num.length()==2 && num.charAt(0)=='-') // If the string is two long and the first character is a negation
				return -Math.E; // Return negative e
			return parseDouble(num.substring(0, num.length()-1))*Math.E;
		}
		return Double.parseDouble(num);
	}

	public String inIntTermsOfPi(double num)
	{
		if (num==0)
			return "0";
		double tmp=num/Math.PI;
		int n=(int)tmp;
		if (n==tmp)
		{
			if (n==-1) // If it is a negative, but otherwise 1
				return "-\u03C0"; // Return negative pi
			return (n==1 ? "" : Integer.toString(n))+"\u03C0";
		}
		else
			return Double.toString(num);
	}

	public String inIntTermsOfE(double num)
	{
		if (num==0)
			return "0";
		double tmp=num/Math.E;
		int n=(int)tmp;
		if (n==tmp)
		{
			if (n==-1) // If it is a negative, but otherwise 1
				return "-e"; // Return negative e
			return (n==1 ? "" : Integer.toString((int)tmp))+"e";
		}
		else
			return Double.toString(num);
	}

	public String inIntTermsOfAny(double num)
	{
		if (Double.isNaN(num)) // "Last-resort" check
			return "ERROR: Nonreal or non-numeric result."; // Trap NaN and return a generic error for it.
		// Because of that check, we can guarantee that NaN's will not be floating around for more than one expression.

		String out=inIntTermsOfPi(num);
		if (!out.equals(Double.toString(num)))
			return out;
		else
			return inIntTermsOfE(num);
	}

	public void zero(View v)
	{
		setZero();
	}

	public void setZero(EditText ev)
	{
		setText("0", ev);
	}

	public void setZero()
	{
		setZero((EditText) findViewById(R.id.mainTextField));
	}

	public void setText(String n, EditText ev)
	{
		ev.setText(n);
		ev.setSelection(0, n.length()); // Ensure the cursor is at the end
	}

	public void setText(String n)
	{
		setText(n, (EditText)findViewById(R.id.mainTextField));
	}

	public void terms(View v)
	{
		EditText ev=(EditText)findViewById(R.id.mainTextField);
		setText(inIntTermsOfAny(parseDouble(ev.getText().toString())), ev);
	}

	public void decimal(View v)
	{
		EditText ev=(EditText)findViewById(R.id.mainTextField);
		setText(Double.toString(parseDouble(ev.getText().toString())), ev);
	}

	public double getValue(final EditText ev) // Parses the content of ev into a double.
	{
		return parseDouble(ev.getText().toString().trim());
	}

	public void doCalculate(final EditText ev, OnClickListener ocl) // Common code for buttons that use the mainCalculateButton.
	{
		doCalculate(ev, ocl, 0);
	}

	public void doCalculate(final EditText ev, OnClickListener ocl, double n) // Common code for buttons that use the mainCalculateButton, setting the default value to n rather than zero.
	{
		setText(Double.toString(n), ev);
		final Button b=(Button)findViewById(R.id.mainCalculateButton);
		b.setVisibility(View.VISIBLE);
		b.setOnClickListener(ocl);
	}

	public void add(View v)
	{
		final EditText ev=(EditText)findViewById(R.id.mainTextField);
		currentValue=getValue(ev);
		doCalculate(ev, new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				v.setOnClickListener(null);
				String num=ev.getText().toString().trim();
				if (num==null || "".equals(num))
					return;
				setText(inIntTermsOfAny(currentValue+parseDouble(num)), ev);
				v.setVisibility(View.GONE);
			}
		});
	}

	public void subtract(View v)<commit_msg>Remove inIntTermsOfAny() bypass from doCalculate()<commit_after>package com.RyanHodin.Calculator;

import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import java.math.BigInteger;

public class MainActivity extends Activity
{
	public double currentValue=0;

	/** Called when the activity is first created. */
	@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB)
		{
			getActionBar().hide();
			if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.ICE_CREAM_SANDWICH)
				findViewById(R.id.mainLayout).setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
		}
		setZero();
	}

	public double parseDouble(String num)
	{
		if (num.indexOf("Error", 0)==0 || num.indexOf("ERROR", 0)==0)
			return 0;
		if (num.charAt(num.length()-1)=='\u03C0')
		{
			if (num.length()==1)
				return Math.PI;
			else if (num.length()==2 && num.charAt(0)=='-') // If the string is two long and the first character is a negation
				return -Math.PI; // Return negative pi
			return parseDouble(num.substring(0, num.length()-1))*Math.PI;
		}
		if (num.charAt(num.length()-1)=='e')
		{
			if (num.length()==1)
				return Math.E;
			else if (num.length()==2 && num.charAt(0)=='-') // If the string is two long and the first character is a negation
				return -Math.E; // Return negative e
			return parseDouble(num.substring(0, num.length()-1))*Math.E;
		}
		return Double.parseDouble(num);
	}

	public String inIntTermsOfPi(double num)
	{
		if (num==0)
			return "0";
		double tmp=num/Math.PI;
		int n=(int)tmp;
		if (n==tmp)
		{
			if (n==-1) // If it is a negative, but otherwise 1
				return "-\u03C0"; // Return negative pi
			return (n==1 ? "" : Integer.toString(n))+"\u03C0";
		}
		else
			return Double.toString(num);
	}

	public String inIntTermsOfE(double num)
	{
		if (num==0)
			return "0";
		double tmp=num/Math.E;
		int n=(int)tmp;
		if (n==tmp)
		{
			if (n==-1) // If it is a negative, but otherwise 1
				return "-e"; // Return negative e
			return (n==1 ? "" : Integer.toString((int)tmp))+"e";
		}
		else
			return Double.toString(num);
	}

	public String inIntTermsOfAny(double num)
	{
		if (Double.isNaN(num)) // "Last-resort" check
			return "ERROR: Nonreal or non-numeric result."; // Trap NaN and return a generic error for it.
		// Because of that check, we can guarantee that NaN's will not be floating around for more than one expression.

		String out=inIntTermsOfPi(num);
		if (!out.equals(Double.toString(num)))
			return out;
		else
			return inIntTermsOfE(num);
	}

	public void zero(View v)
	{
		setZero();
	}

	public void setZero(EditText ev)
	{
		setText("0", ev);
	}

	public void setZero()
	{
		setZero((EditText) findViewById(R.id.mainTextField));
	}

	public void setText(String n, EditText ev)
	{
		ev.setText(n);
		ev.setSelection(0, n.length()); // Ensure the cursor is at the end
	}

	public void setText(String n)
	{
		setText(n, (EditText)findViewById(R.id.mainTextField));
	}

	public void terms(View v)
	{
		EditText ev=(EditText)findViewById(R.id.mainTextField);
		setText(inIntTermsOfAny(parseDouble(ev.getText().toString())), ev);
	}

	public void decimal(View v)
	{
		EditText ev=(EditText)findViewById(R.id.mainTextField);
		setText(Double.toString(parseDouble(ev.getText().toString())), ev);
	}

	public double getValue(final EditText ev) // Parses the content of ev into a double.
	{
		return parseDouble(ev.getText().toString().trim());
	}

	public void doCalculate(final EditText ev, OnClickListener ocl) // Common code for buttons that use the mainCalculateButton.
	{
		doCalculate(ev, ocl, 0);
	}

	public void doCalculate(final EditText ev, OnClickListener ocl, double n) // Common code for buttons that use the mainCalculateButton, setting the default value to n rather than zero.
	{
		setText(inIntTermsOfAny(n), ev);
		final Button b=(Button)findViewById(R.id.mainCalculateButton);
		b.setVisibility(View.VISIBLE);
		b.setOnClickListener(ocl);
	}

	public void add(View v)
	{
		final EditText ev=(EditText)findViewById(R.id.mainTextField);
		currentValue=getValue(ev);
		doCalculate(ev, new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				v.setOnClickListener(null);
				String num=ev.getText().toString().trim();
				if (num==null || "".equals(num))
					return;
				setText(inIntTermsOfAny(currentValue+parseDouble(num)), ev);
				v.setVisibility(View.GONE);
			}
		});
	}

	public void subtract(View v)
{'fraction_non_alphanumeric': 0.14162002323371, 'fraction_numerical': 0.008448621818565847, 'mean_word_length': 4.031880977683316, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '372238', 'n_tokens_mistral': 3650, 'n_tokens_neox': 3240, 'n_words': 795}