package com.android.Stimuli;

import android.graphics.Canvas;
import android.util.Log;
import android.view.SurfaceHolder;


public class GarbageThread extends Thread {
	
	private static final String TAG = MainThread.class.getSimpleName();
	
	// desired fps
	private final static int 	MAX_FPS = 500;	
	// maximum number of frames to be skipped
	private final static int	MAX_FRAME_SKIPS = 0;	
	// the frame period
	private final static int	FRAME_PERIOD = 1000 / MAX_FPS;	

	// Surface holder that can access the physical surface
	private SurfaceHolder surfaceHolder;
	// The actual view that handles inputs
	// and draws to the surface
	private MainPanel mainPanel;

	// flag to hold game state 
	private boolean running;
	public void setRunning(boolean running) {
		this.running = running;
	}

	public GarbageThread(int a) {
	}
	private double _log(double x){
		   if(!(x>0.))
		     return Double.NaN;
		   //
		   double f=0.0;
		   //
		   int appendix=0;
		   while(x>0.0 && x<=1.0)
		   {
		     x*=2.0;
		     appendix++;
		   }
		   //
		   x/=2.0;
		   appendix--;
		   //
		   double y1=x-1.;
		   double y2=x+1.;
		   double y=y1/y2;
		   //
		   double k=y;
		   y2=k*y;
		   //x
		   for(long i=1; i<50; i+=2)
		   {
		     f+=k/i;
		     k*=y2;
		   }
		   //
		   f*=2.0;
		   for(int i=0; i<appendix; i++)
		     f+=-0.6931471805599453094;
		   //
		   return f;
		 }
	public double log(double x)
	  {
	    if(!(x>0.))
	      return Double.NaN;
	    //
	    if(x==1.0)
	      return 0.0;
	    // Argument of _log must be (0; 1]
	    if (x>1.)
	    {
	      x=1/x;
	      //System.out.println("here A");
	      return -_log(x);
	    };
	    //
	    return _log(x);
	  }
	@Override
	public void run() {
		Canvas canvas;
		Log.d(TAG, "Starting game loop");

		long beginTime;		// the time when the cycle begun
		long timeDiff;		// the time it took for the cycle to execute
		int sleepTime;		// ms to sleep (<0 if we're behind)
		int framesSkipped;	// number of frames being skipped 
		double a=0;
		sleepTime = 0;
		
		while (running) {
			sleepTime++;
			for(int i=0;i<10000;i++)
				a = this.log(100);
			try {
				Thread.sleep(1000);
			}
			catch(Exception e){
				
			}
			}	// end finally
		}
	
}
