   }
 }
 
+// http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1207226548
+void printDouble( double val, byte precision){
+  // prints val with number of decimal places determine by precision
+  // precision is a number from 0 to 6 indicating the desired decimial places
+  // example: printDouble( 3.1415, 2); // prints 3.14 (two decimal places)
+
+  Serial.print (int(val));  //prints the int part
+  if( precision > 0) {
+    Serial.print("."); // print the decimal point
+    unsigned long frac;
+    unsigned long mult = 1;
+    byte padding = precision -1;
+    while(precision--)
+	 mult *=10;
+
+    if(val >= 0)
+	frac = (val - int(val)) * mult;
+    else
+	frac = (int(val)- val ) * mult;
+    unsigned long frac1 = frac;
+    while( frac1 /= 10 )
+	padding--;
+    while(  padding--)
+	Serial.print("0");
+    Serial.print(frac,DEC) ;
+  }
+}
+
+double fixedPointDistance(uint32_t a1, uint32_t a2, uint32_t b1, uint32_t b2)
+{
+  return ((int64_t) b2 - (int64_t) b1) / two_to_32 + (int32_t) (b1 - a1);
+}
+
 void loop() {
   static bool flag = true;
   if (flag) {

               buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V) {
      es.ES_make_echo_reply_from_request(buf, length);
    } else if (buf[IP_PROTO_P] == IP_PROTO_UDP_V && buf[UDP_DST_PORT_L_P] == ntpPort && length == UDP_DATA_P + NTP_PACKET_SIZE) {
      // NOTE: requires disabling the pass-only-arp-broadcast filter from enc28j60
      Serial.println("Received ntp packet");
      uint32_t a = buf[UDP_DATA_P + TRANSMIT_TIMESTAMP_P + 0];
      uint32_t b = buf[UDP_DATA_P + TRANSMIT_TIMESTAMP_P + 1];
      uint32_t c = buf[UDP_DATA_P + TRANSMIT_TIMESTAMP_P + 2];

  pinMode(debug, OUTPUT);
  pinMode(in, INPUT);
  digitalWrite(out, HIGH);
  digitalWrite(debug, LOW);
  ethernet.setup(mac, ip, port);
  Serial.begin(9600);
  Serial.println("Start.");
  Serial.print("Fractions per overflow: "); Serial.println(fractionsPerOverflow);
  setupTimer();
}

