# HG changeset patch
# User JeanDo
# Date 1316731377 -7200
# Node ID 274689f46b1a6384497e58f81030bb61f0c0a762
# Parent  770456638c666e249c866002c41c1d7397d885f1
BUGFIX round depth before checking surface

diff -r 770456638c66 -r 274689f46b1a code_part1/OSTC_code_c_part2/p2_deco.c
--- a/code_part1/OSTC_code_c_part2/p2_deco.c	Thu Sep 01 14:39:44 2011 +0200
+++ b/code_part1/OSTC_code_c_part2/p2_deco.c	Fri Sep 23 00:42:57 2011 +0200
@@ -1547,6 +1547,8 @@
     //---- Loop until first stop, gas switch, or surface is reached ----------
  	for(;;)
   	{
+        overlay short tmp;              // Rounded distance to surface.
+
         // Try ascending 1 full minute.
 	    temp_deco -= 10*METER_TO_BAR;   // 1 min, at 10m/min. ~ 1bar.
 
@@ -1561,15 +1563,17 @@
         }
 
         // Did we reach surface ?
-        if( temp_deco <= pres_surface )
+        // NOTE: we should round BEFORE checking surface is reached.
+        tmp = (short)(0.5 + (temp_deco - pres_surface) * BAR_TO_METER);
+        if( tmp <= 0 )
         {
             temp_deco = pres_surface;   // Yes: finished !
             break;
         }
 
         // Check for gas change below new depth ?
-        temp_depth_limit = (int)(0.5 + (temp_deco - pres_surface) * BAR_TO_METER);
-        assert( temp_depth_limit > 0);
+        assert( 0 < tmp && tmp < 255);
+        temp_depth_limit = (unsigned char)tmp;
 
         if( gas_switch_deepest() )
         {