Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

utl.c

Go to the documentation of this file.
00001 #include "calc.h"
00002 
00003 void prepare_rpn_result_2(calc_number_t *rpn, TCHAR *buffer, int size, int base)
00004 {
00005     calc_number_t tmp;
00006     int    width;
00007 
00008     switch (base) {
00009     case IDC_RADIO_HEX:
00010         _stprintf(buffer, TEXT("%I64X"), rpn->i);
00011         break;
00012     case IDC_RADIO_DEC:
00013 /*
00014  * Modifed from 17 to 16 for fixing this bug:
00015  * 14+14+6.3+6.3= 40.5999999 instead of 40.6
00016  * So, it's probably better to leave the least
00017  * significant digit out of the display.
00018  */
00019 #define MAX_LD_WIDTH    16
00020         /* calculate the width of integer number */
00021         width = (rpn->f==0) ? 1 : (int)log10(fabs(rpn->f))+1;
00022         if (calc.sci_out == TRUE || width > MAX_LD_WIDTH || width < -MAX_LD_WIDTH)
00023             _stprintf(buffer, TEXT("%#e"), rpn->f);
00024         else {
00025             TCHAR *ptr, *dst;
00026 
00027             ptr = buffer + _stprintf(buffer, TEXT("%#*.*f"), width, ((MAX_LD_WIDTH-width-1)>=0) ? MAX_LD_WIDTH-width-1 : 0, rpn->f);
00028             /* format sring ensures there is a '.': */
00029             dst = _tcschr(buffer, TEXT('.'));
00030             while (--ptr > dst)
00031                 if (*ptr != TEXT('0'))
00032                     break;
00033 
00034             /* put the string terminator for removing the final '0' (if any) */
00035             ptr[1] = TEXT('\0');
00036             /* check if the number finishes with '.' */
00037             if (ptr == dst)
00038                 /* remove the dot (it will be re-added later) */
00039                 ptr[0] = TEXT('\0');
00040         }
00041 #undef MAX_LD_WIDTH
00042         break;
00043     case IDC_RADIO_OCT:
00044         _stprintf(buffer, TEXT("%I64o"), rpn->i);
00045         break;
00046     case IDC_RADIO_BIN:
00047         if (rpn->i == 0) {
00048             buffer[0] = TEXT('0');
00049             buffer[1] = TEXT('\0');
00050             break;
00051         }
00052         tmp = *rpn;
00053         buffer[0] = TEXT('\0');
00054         while (tmp.u) {
00055             memmove(buffer+1, buffer, (size-1)*sizeof(TCHAR));
00056             if (tmp.u & 1)
00057                 calc.buffer[0] = TEXT('1');
00058             else
00059                 calc.buffer[0] = TEXT('0');
00060             tmp.u >>= 1;
00061         }
00062         break;
00063     }
00064 }
00065 
00066 void convert_text2number_2(calc_number_t *a)
00067 {
00068     TCHAR *ptr;
00069 
00070     switch (calc.base) {
00071     case IDC_RADIO_HEX:
00072         _stscanf(calc.buffer, TEXT("%I64X"), &(a->i));
00073         break;
00074     case IDC_RADIO_DEC:
00075         _stscanf(calc.buffer, TEXT("%lf"), &(a->f));
00076         break;
00077     case IDC_RADIO_OCT:
00078         _stscanf(calc.buffer, TEXT("%I64o"), &(a->i));
00079         break;
00080     case IDC_RADIO_BIN:
00081         ptr = calc.buffer;
00082         a->i = 0;
00083         while (*ptr != TEXT('\0')) {
00084             a->i <<= 1;
00085             if (*ptr++ == TEXT('1'))
00086                 a->i |= 1;
00087         }
00088         break;
00089     }
00090 }
00091 
00092 void convert_real_integer(unsigned int base)
00093 {
00094     switch (base) {
00095     case IDC_RADIO_DEC:
00096         calc.code.f = (double)calc.code.i;
00097         break;
00098     case IDC_RADIO_OCT:
00099     case IDC_RADIO_BIN:
00100     case IDC_RADIO_HEX:
00101         if (calc.base == IDC_RADIO_DEC) {
00102             calc.code.i = (__int64)calc.code.f;
00103             apply_int_mask(&calc.code);
00104         }
00105         break;
00106     }
00107 }

Generated on Thu Feb 9 04:38:58 2012 for ReactOS by doxygen 1.6.3

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.