Canola  0.8.D001
lib/number/right-shift.cc
Go to the documentation of this file.
00001 //
00002 // canola - canon canola 1614p emulator
00003 // Copyright (C) 2011, 2012 Peter Miller
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, version 3, as
00007 // published by the Free Software Foundation.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License along
00015 // with this program. If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 #include <lib/ac/assert.h>
00019 
00020 #include <lib/number.h>
00021 
00022 
00023 void
00024 number::right_shift(void)
00025 {
00026     // <question>
00027     // When you have an overflow on the screen (e.g. divide by zero,
00028     // 9999999999999999) when you press [->] what is displayed?
00029     // Is it "0.", "999999999999999.", or something else?
00030     // </question>
00031 
00032     // Instruction Manual, p. 21:
00033     //
00034     // "If the number of integral digits exceeds 16, the position of
00035     // the decimal point automatically indicates the number of integral
00036     // digits that have been dropped.  (For instance, if 3 integral
00037     // digits are dropped, the decimal point appears after the third
00038     // digit from the left.)  In this case, the overflow lamp lights,
00039     // but the actual position of the decimal point is preserved within
00040     // the registers."
00041     //
00042     // Note: from the LEFT.
00043     //
00044     if (has_overflowed())
00045     {
00046         // <question>
00047         // When a calculation overflows, an you press [->] to clear it,
00048         // what happens to the display?  Is the overflow light cleared,
00049         // but the value on the screen changes?  Does the value on the
00050         // screen becoem 15 digits, with a leading 0 digit?  Does the
00051         // 17th digit get shifted in?
00052         // </question>
00053         //
00054         // This code keeps the right-most 16 digits, and discards the rest.
00055         // A fairly literal interpretation of clearing the overflow indication.
00056         //
00057         assert(decimal == 0);
00058         value = value.right_16();
00059     }
00060     else
00061     {
00062         value = value.shift_right(1);
00063         if (decimal > 0)
00064             --decimal;
00065     }
00066     if (value.is_zero())
00067         negative = false;
00068 }
00069 
00070 
00071 // vim: set ts=8 sw=4 et :