示例#1
0
char		*ft_itoa_base(int n, int base)
{
	char	*str;
	int		i;

	i = numb(n, base);
	if (n == -2147483648)
		return (ft_strdup("-2147483648"));
	if (n < 0)
		i = i + 1;
	str = ft_strnew(i + 1);
	if (!str)
		return (NULL);
	str[0] = '0';
	if (n < 0)
	{
		str[0] = '-';
		n = -n;
	}
	while (i >= 0 && n != 0)
	{
		str[i] = ft_int_base(n, base) + 48;
		n = n / base;
		i = i - 1;
	}
	return (str);
}
示例#2
0
文件: ft_itoa.c 项目: fpolini/fillit
char		*ft_itoa(int n)
{
	char	*str;
	int		i;

	i = numb(n);
	if (n == -2147483648)
		return (ft_strdup("-2147483648"));
	if (n < 0)
		i = i + 1;
	str = ft_strnew(i + 1);
	if (!str)
		return (NULL);
	str[0] = '0';
	if (n < 0)
	{
		str[0] = '-';
		n = -n;
	}
	while (i >= 0 && n != 0)
	{
		str[i] = (n % 10) + 48;
		n = n / 10;
		i = i - 1;
	}
	return (str);
}
示例#3
0
文件: graph.c 项目: andreiw/polaris
void
limread(struct xy *p, int *argcp, char ***argvp)
{
	if(*argcp>1 && (*argvp)[1][0]=='l') {
		(*argcp)--;
		(*argvp)++;
		p->xf = log10;
	}
	if(!numb(&p->xlb,argcp,argvp))
		return;
	p->xlbf = 1;
	if(!numb(&p->xub,argcp,argvp))
		return;
	p->xubf = 1;
	if(!numb(&p->xquant,argcp,argvp))
		return;
	p->xqf = 1;
}
示例#4
0
int main()
{
	stack *st = NULL;
	char a[20];//вход, счётчик i
	char b[20];//вывод, счётчик j
	printf("infix: ");
	scanf("%s", a);
	int i = 0;
	int j = 0;
	while(a[i] != '\0')           
	{
		st = clbr(st, a[i], b, j);
		operand(a[i], b, j);
		st = opbr(st, a[i]);
		st = oper(st, a[i], b, j);
		i++;                                    
	}
	st = end(st, b, j);
	printf("postfix: %s\n", b);
	
	i = 0;
	while (b[i] != '\0')
	{
		if (numb(b[i]))//число - в стек
			st = push (st, b[i]);
		else//операция - вытащить два числа и прооперировать
		{
			int a1 = (int(pop(&st)) - int('0'));
			int b1 = (int(pop(&st)) - int('0'));
			int c = 0;
			switch (b[i])
			{
			case '+':
				c = a1 + b1;
				break;
			case '-':
				c = b1 - a1;
				break;
			case '*':
				c = b1 * a1;
				break;
			case '/':
				c = b1 / a1;
				break;
			}
			st = push (st, (c + int('0')));
		}
		i++;
	}
	int res = (int(pop(&st)) - int('0'));
	printf("result: %d\ninput something to close\n", res);

	scanf("%*s");
	return 0;
}
示例#5
0
文件: pdate.c 项目: 99years/plan9
void
ptime(double d)
{
    int h, m, s;
    char *mer;
    Tim t;

    if(flags['s']) {
        /* hour minute */
        dtsetup(d + .5/(24*60), &t);
        h = t.ifa[3];
        m = floor(t.ifa[4]);

        mer = "AM";
        if(h >= 12) {
            mer = "PM";
            h -= 12;
        }
        if(h == 0)
            h = 12;
        numb(h);
        if(m < 10) {
            if(m == 0) {
                print("%s exactly ...", mer);
                return;
            }
            print("O ");
        }
        numb(m);
        print("%s ...", mer);
        return;
    }
    /* hour minute second */
    dtsetup(d, &t);
    h = t.ifa[3];
    m = floor(t.ifa[4]);
    s = floor((t.ifa[4]-m) * 60);
    print("%.2d:%.2d:%.2d %.*s", h, m, s, utfnlen(t.tz, 3), t.tz);
}
示例#6
0
文件: pdate.c 项目: 99years/plan9
void
pdate(double d)
{
    int i;
    Tim t;

    dtsetup(d, &t);
    if(flags['s']) {
        i = t.ifa[1];
        print("%s ", month[i-1]);
        i = t.ifa[2];
        numb(i);
        print("...");
        return;
    }

    /* year month day */
    print("%4d %2d %2d",
          (int)t.ifa[0],
          (int)t.ifa[1],
          (int)t.ifa[2]);
}
NetworkManager::~NetworkManager(void)
{
	numb();
}
示例#8
0
文件: graph.c 项目: andreiw/polaris
void
setopt(int argc, char **argv)
{
	char *p1, *p2;
	float temp;

	xd.xlb = yd.xlb = INF;
	xd.xub = yd.xub = -INF;
	while(--argc > 0) {
		argv++;
again:		switch(argv[0][0]) {
		case '-':
			argv[0]++;
			goto again;
		case 'l': /* label for plot */
			p1 = titlebuf;
			if (argc>=2) {
				argv++;
				argc--;
				p2 = argv[0];
				while (*p1++ = *p2++);
			}
			break;

		case 'd':	/*disconnected,obsolete option*/
		case 'm': /*line mode*/
			mode = 0;
			if(!numb(&temp,&argc,&argv))
				break;
			if(temp>=sizeof(modes)/sizeof(*modes))
				mode = 1;
			else if(temp>=0)
				mode = temp;
			break;

		case 'a': /*automatic abscissas*/
			absf = 1;
			dx = 1;
			if(!numb(&dx,&argc,&argv))
				break;
			if(numb(&absbot,&argc,&argv))
				absf = 2;
			break;

		case 's': /*save screen, overlay plot*/
			erasf = 0;
			break;

		case 'g': /*grid style 0 none, 1 ticks, 2 full*/
			gridf = 0;
			if(!numb(&temp,&argc,&argv))
				temp = argv[0][1]-'0';	/*for caompatibility*/
			if(temp>=0&&temp<=2)
				gridf = temp;
			break;

		case 'c': /*character(s) for plotting*/
			if(argc >= 2) {
				symbf = 1;
				plotsymb = argv[1];
				argv++;
				argc--;
			}
			break;

		case 't':	/*transpose*/
			transf = 1;
			break;
		case 'b':	/*breaks*/
			brkf = 1;
			break;
		case 'x':	/*x limits */
			limread(&xd,&argc,&argv);
			break;
		case 'y':
			limread(&yd,&argc,&argv);
			break;
		case 'h': /*set height of plot */
			if(!numb(&yd.xsize, &argc,&argv))
				badarg();
			break;
		case 'w': /*set width of plot */
			if(!numb(&xd.xsize, &argc, &argv))
				badarg();
			break;
		case 'r': /* set offset to right */
			if(!numb(&xd.xoff, &argc, &argv))
				badarg();
			break;
		case 'u': /*set offset up the screen*/
			if(!numb(&yd.xoff,&argc,&argv))
				badarg();
			break;
		default:
			badarg();
		}
	}
}
double integrateD(const KernelD & F, const Element & e)
{
    double result = 0.0;

    // Get the quadrature rules for azimuthal and polar integrations
    namespace mpl = boost::mpl;
    typedef typename mpl::at<rules_map, mpl::int_<PhiPoints> >::type PhiPolicy;
    typedef typename mpl::at<rules_map, mpl::int_<ThetaPoints> >::type ThetaPolicy;
    QuadratureRule<PhiPolicy> phiRule;
    QuadratureRule<ThetaPolicy> thetaRule;
    int upper_phi = PhiPoints / 2; // Upper limit for loop on phi points
    int upper_theta = ThetaPoints / 2; // Upper limit for loop on theta points

    // Extract relevant data from Element
    int nVertices = e.nVertices();
    Eigen::Vector3d normal = e.normal();
    Sphere sph = e.sphere();
    Eigen::Matrix3Xd vertices = e.vertices();
    Eigen::Matrix3Xd arcs = e.arcs();

    // Calculation of the tangent and the bitangent (binormal) vectors
    // Tangent, Bitangent and Normal form a local reference frame:
    // T <-> x; B <-> y; N <-> z
    Eigen::Vector3d tangent, bitangent;
    tangent_and_bitangent(normal, tangent, bitangent);

    std::vector<double> theta(nVertices), phi(nVertices), phinumb(nVertices+1);
    std::vector<int> numb(nVertices+1);
    // Clean-up heap crap
    std::fill_n(theta.begin(),   nVertices,   0.0);
    std::fill_n(phi.begin(),     nVertices,   0.0);
    std::fill_n(numb.begin(),    nVertices+1, 0);
    std::fill_n(phinumb.begin(), nVertices+1, 0.0);
    // Populate arrays and redefine tangent and bitangent
    e.spherical_polygon(tangent, bitangent, theta, phi, phinumb, numb);

    // Actual integration occurs here
    for (int i = 0; i < nVertices; ++i) { // Loop on edges
        double phiLower = phinumb[i]; // Lower vertex of edge
        double phiUpper = phinumb[i+1]; // Upper vertex of edge
        double phiA = (phiUpper - phiLower) / 2.0;
        double phiB = (phiUpper + phiLower) / 2.0;
        double thetaLower = theta[numb[i]];
        double thetaUpper = theta[numb[i+1]];
        double thetaMax = 0.0;
        Eigen::Vector3d oc = (arcs.col(i) - sph.center) / sph.radius;
        double oc_norm = oc.norm();
        double oc_norm2 = std::pow(oc_norm, 2);
        for (int j = 0; j < upper_phi; ++j) { // Loop on Gaussian points: phi integration
            for (int k = 0; k <= 1; ++k) {
                double ph = (2*k - 1) * phiA * phiRule.abscissa(j) + phiB;
                double cos_phi = std::cos(ph);
                double sin_phi = std::sin(ph);
                if (oc_norm2 < 1.0e-07) { // This should check if oc_norm2 is zero
                    double cotg_thmax = (std::sin(ph-phiLower) / std::tan(thetaUpper) + std::sin(phiUpper-ph) / std::tan(
                                thetaLower)) / std::sin(phiUpper - phiLower);
                    thetaMax = std::atan(1.0 / cotg_thmax);
                } else {
                    Eigen::Vector3d scratch;
                    scratch << tangent.dot(oc), bitangent.dot(oc), normal.dot(oc);
                    double aa = std::pow(tangent.dot(oc)*cos_phi + bitangent.dot(oc)*sin_phi,
                            2) + std::pow(normal.dot(oc), 2);
                    double bb = -normal.dot(oc) * oc_norm2;
                    double cc = std::pow(oc_norm2,
                            2) - std::pow(tangent.dot(oc)*cos_phi + bitangent.dot(oc)*sin_phi, 2);
                    double ds = std::pow(bb, 2) - aa*cc;
                    if (ds < 0.0) ds = 0.0;
                    double cs = (-bb + std::sqrt(ds)) / aa;
                    if (cs > 1.0) cs = 1.0;
                    if (cs < -1.0) cs = 1.0;
                    thetaMax = std::acos(cs);
                }
                double thetaA = thetaMax / 2.0;
                double scratch = 0.0;
                if (!(thetaMax < 1.0e-08)) {
                    for (int l = 0; l < upper_theta; ++l) { // Loop on Gaussian points: theta integration
                        for (int m = 0; m <= 1; ++m) {
                            double th = (2*m - 1) * thetaA  * thetaRule.abscissa(l) + thetaA;
                            double cos_theta = std::cos(th);
                            double sin_theta = std::sin(th);
                            Eigen::Vector3d point;
                            point(0) = tangent(0) * sin_theta * cos_phi
                                + bitangent(0) * sin_theta * sin_phi
                                + normal(0) * (cos_theta - 1.0);
                            point(1) = tangent(1) * sin_theta * cos_phi
                                + bitangent(1) * sin_theta * sin_phi
                                + normal(1) * (cos_theta - 1.0);
                            point(2) = tangent(2) * sin_theta * cos_phi
                                + bitangent(2) * sin_theta * sin_phi
                                + normal(2) * (cos_theta - 1.0);
                            double value = F(e.normal(),
                                    Eigen::Vector3d::Zero(),
                                    point); // Evaluate integrand at Gaussian point
                            scratch += std::pow(sph.radius, 2) * value * sin_theta * thetaA * thetaRule.weight(l);
                        }
                    }
                    result += scratch * phiA * phiRule.weight(j);
                }
            }
        }
    }
    return result;
}
示例#10
0
文件: t4.c 项目: 00001/plan9port
void
readspec(void)
{
	int	icol, c, sawchar, stopc, i;
	char	sn[10], *snp, *temp;

	sawchar = icol = 0;
	while (c = get1char()) {
		switch (c) {
		default:
			if (c != tab) {
				char buf[64];
				sprint(buf, "bad table specification character %c", c);
				error(buf);
			}
		case ' ': /* note this is also case tab */
			continue;
		case '\n':
			if (sawchar == 0) 
				continue;
		case ',':
		case '.': /* end of table specification */
			ncol = max(ncol, icol);
			if (lefline[ncol][nclin] > 0) {
				ncol++; 
				rightl++;
			};
			if (sawchar)
				nclin++;
			if (nclin >= MAXHEAD)
				error("too many lines in specification");
			icol = 0;
			if (ncol == 0 || nclin == 0)
				error("no specification");
			if (c == '.') {
				while ((c = get1char()) && c != '\n')
					if (c != ' ' && c != '\t')
						error("dot not last character on format line");
				/* fix up sep - default is 3 except at edge */
				for (icol = 0; icol < ncol; icol++)
					if (sep[icol] < 0)
						sep[icol] =  icol + 1 < ncol ? 3 : 2;
				if (oncol == 0)
					oncol = ncol;
				else if (oncol + 2 < ncol)
					error("tried to widen table in T&, not allowed");
				return;
			}
			sawchar = 0;
			continue;
		case 'C': 
		case 'S': 
		case 'R': 
		case 'N': 
		case 'L':  
		case 'A':
			c += ('a' - 'A');
		case '_': 
			if (c == '_') 
				c = '-';
		case '=': 
		case '-':
		case '^':
		case 'c': 
		case 's': 
		case 'n': 
		case 'r': 
		case 'l':  
		case 'a':
			style[icol][nclin] = c;
			if (c == 's' && icol <= 0)
				error("first column can not be S-type");
			if (c == 's' && style[icol-1][nclin] == 'a') {
				Bprint(&tabout, ".tm warning: can't span a-type cols, changed to l\n");
				style[icol-1][nclin] = 'l';
			}
			if (c == 's' && style[icol-1][nclin] == 'n') {
				Bprint(&tabout, ".tm warning: can't span n-type cols, changed to c\n");
				style[icol-1][nclin] = 'c';
			}
			icol++;
			if (c == '^' && nclin <= 0)
				error("first row can not contain vertical span");
			if (icol > qcol)
				error("too many columns in table");
			sawchar = 1;
			continue;
		case 'b': 
		case 'i':
			c += 'A' - 'a';
		case 'B': 
		case 'I':
			if (icol == 0) 
				continue;
			snp = font[icol-1][nclin];
			snp[0] = (c == 'I' ? '2' : '3');
			snp[1] = 0;
			continue;
		case 't': 
		case 'T':
			if (icol > 0)
				flags[icol-1][nclin] |= CTOP;
			continue;
		case 'd': 
		case 'D':
			if (icol > 0)
				flags[icol-1][nclin] |= CDOWN;
			continue;
		case 'f': 
		case 'F':
			if (icol == 0) 
				continue;
			snp = font[icol-1][nclin];
			snp[0] = snp[1] = stopc = 0;
			for (i = 0; i < 2; i++) {
				c = get1char();
				if (i == 0 && c == '(') {
					stopc = ')';
					c = get1char();
				}
				if (c == 0) 
					break;
				if (c == stopc) {
					stopc = 0; 
					break;
				}
				if (stopc == 0)  
					if (c == ' ' || c == tab ) 
						break;
				if (c == '\n' || c == '|') {
					un1getc(c); 
					break;
				}
				snp[i] = c;
				if (c >= '0' && c <= '9') 
					break;
			}
			if (stopc) 
				if (get1char() != stopc)
					error("Nonterminated font name");
			continue;
		case 'P': 
		case 'p':
			if (icol <= 0) 
				continue;
			temp = snp = csize[icol-1][nclin];
			while (c = get1char()) {
				if (c == ' ' || c == tab || c == '\n') 
					break;
				if (c == '-' || c == '+')
					if (snp > temp)
						break;
					else
						*snp++ = c;
				else if (digit(c))
					*snp++ = c;
				else 
					break;
				if (snp - temp > 4)
					error("point size too large");
			}
			*snp = 0;
			if (atoi(temp) > 36)
				error("point size unreasonable");
			un1getc (c);
			continue;
		case 'V': 
		case 'v':
			if (icol <= 0) 
				continue;
			temp = snp = vsize[icol-1][nclin];
			while (c = get1char()) {
				if (c == ' ' || c == tab || c == '\n') 
					break;
				if (c == '-' || c == '+')
					if (snp > temp)
						break;
					else
						*snp++ = c;
				else if (digit(c))
					*snp++ = c;
				else 
					break;
				if (snp - temp > 4)
					error("vertical spacing value too large");
			}
			*snp = 0;
			un1getc(c);
			continue;
		case 'w': 
		case 'W':
			snp = cll [icol-1];
			/* Dale Smith didn't like this check - possible to have two text blocks
		   of different widths now ....
			if (*snp)
				{
				Bprint(&tabout, "Ignored second width specification");
				continue;
				}
		/* end commented out code ... */
			stopc = 0;
			while (c = get1char()) {
				if (snp == cll[icol-1] && c == '(') {
					stopc = ')';
					continue;
				}
				if ( !stopc && (c > '9' || c < '0'))
					break;
				if (stopc && c == stopc)
					break;
				*snp++ = c;
			}
			*snp = 0;
			if (snp - cll[icol-1] > CLLEN)
				error ("column width too long");
			if (!stopc)
				un1getc(c);
			continue;
		case 'e': 
		case 'E':
			if (icol < 1) 
				continue;
			evenup[icol-1] = 1;
			evenflg = 1;
			continue;
		case 'z': 
		case 'Z': /* zero width-ignre width this item */
			if (icol < 1) 
				continue;
			flags[icol-1][nclin] |= ZEROW;
			continue;
		case 'u': 
		case 'U': /* half line up */
			if (icol < 1) 
				continue;
			flags[icol-1][nclin] |= HALFUP;
			continue;
		case '0': 
		case '1': 
		case '2': 
		case '3': 
		case '4':
		case '5': 
		case '6': 
		case '7': 
		case '8': 
		case '9':
			sn[0] = c;
			snp = sn + 1;
			while (digit(*snp++ = c = get1char()))
				;
			un1getc(c);
			sep[icol-1] = max(sep[icol-1], numb(sn));
			continue;
		case '|':
			lefline[icol][nclin]++;
			if (icol == 0) 
				left1flg = 1;
			continue;
		}
	}
	error("EOF reading table specification");
}
示例#11
0
BamKeysPrefsWindow::BamKeysPrefsWindow()
	: BWindow(BRect(40, 30, 40 + WIDTH, 30 + HEIGHT), "BamKeys",
			B_TITLED_WINDOW, B_NOT_ZOOMABLE)// | B_NOT_RESIZABLE)
{
	fModified = false;
	fRootView = new BBox(BRect(0, 0, WIDTH, HEIGHT), 
						"root_view", B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER);
	
	fRootView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	AddChild(fRootView);
	
	// Screen area selection box
	fScreenBox = new BBox(BRect(10, 10, ((WIDTH / 3) * 2) - 5, (HEIGHT - 50)), 
						"screen_box", B_FOLLOW_ALL, B_WILL_DRAW, B_FANCY_BORDER);
	BRect gridRect = fScreenBox->Frame();
	gridRect.OffsetTo(0, 0);
	gridRect.InsetBy(5, 5);
	fGrid = new BamKeysGridControl(gridRect, "screen_grid", "", new BMessage('grid'));
	fScreenBox->AddChild(fGrid);
	
	// Settings Box
	fSettingBox = new BBox(BRect(((WIDTH / 3) * 2) + 5, 10, WIDTH - 10, (HEIGHT - 50)),
						"settings_box", B_FOLLOW_RIGHT | B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW, B_FANCY_BORDER);
	
	BRect itmRect = fSettingBox->Frame();
	itmRect.Set(5, 10, itmRect.Width() - 5, (itmRect.Height() - 10) / 8);
	
	// Filter Enabled
	fChkEnabled = new BCheckBox(itmRect, "chkGrid", "Enable BamKeys", new BMessage('fltr'), B_FOLLOW_TOP | B_FOLLOW_RIGHT);
	fChkEnabled->SetValue(fGrid->IsFiltering() ? B_CONTROL_ON : B_CONTROL_OFF);
	fSettingBox->AddChild(fChkEnabled);
	
	itmRect.OffsetBy(0, itmRect.Height());

	// Rows and Columns
	int32 rows;
	int32 columns;
	fGrid->GetSize(&rows, &columns);
	
	BPopUpMenu *mnuRows = new BPopUpMenu("");
	for (int i = 1; i <= MAX_DIVIDE; i++) {
		BString numb("");
		numb << i;
		BMenuItem *mnuItem = new BMenuItem(numb.String(), new BMessage('rowC'));
		mnuRows->AddItem(mnuItem);
		if (i == rows) {
			mnuItem->SetMarked(true);
		}
	}
	
	fMnuFldRows = new BMenuField(itmRect, "mnuRows", "Rows:", mnuRows, B_FOLLOW_TOP | B_FOLLOW_RIGHT);
	fSettingBox->AddChild(fMnuFldRows);
	
	
	itmRect.OffsetBy(0, itmRect.Height());
	
	BPopUpMenu *mnuColumns = new BPopUpMenu("");
	for (int i = 1; i <= MAX_DIVIDE; i++) {
		BString numb("");
		numb << i;
		BMenuItem *mnuItem = new BMenuItem(numb.String(), new BMessage('colC'));
		mnuColumns->AddItem(mnuItem);
		if (i == columns) {
			mnuItem->SetMarked(true);
		}
	}
	
	fMnuFldColumns = new BMenuField(itmRect, "mnuCols", "Columns:", mnuColumns, B_FOLLOW_TOP | B_FOLLOW_RIGHT);
	fSettingBox->AddChild(fMnuFldColumns);
	
	itmRect.OffsetBy(0, itmRect.Height());
	// Hotkey
	BRect stringRect(itmRect);
	stringRect.OffsetBy(0, -(itmRect.Height() / 3));
	fStrHotKey = new BStringView(stringRect, "lblModifiers", "Modifiers:", B_FOLLOW_TOP | B_FOLLOW_LEFT);
	fSettingBox->AddChild(fStrHotKey);
	itmRect.OffsetBy(0, itmRect.Height());

	// Caps Lock
	fCapsLock = new BamKeysKeyView(itmRect, "capsLock", B_CAPS_LOCK, B_FOLLOW_TOP | B_FOLLOW_LEFT);
	fSettingBox->AddChild(fCapsLock);
	itmRect.OffsetBy(0, itmRect.Height());
	
	// Num Lock
	fNumLock = new BamKeysKeyView(itmRect, "numLock", B_NUM_LOCK, B_FOLLOW_TOP | B_FOLLOW_LEFT);
	fSettingBox->AddChild(fNumLock);
	itmRect.OffsetBy(0, itmRect.Height());

	// Scroll Lock
	fScrlLock = new BamKeysKeyView(itmRect, "scrollLock", B_SCROLL_LOCK, B_FOLLOW_TOP | B_FOLLOW_LEFT);
	fSettingBox->AddChild(fScrlLock);
	itmRect.OffsetBy(0, itmRect.Height());
	
	BPoint half = itmRect.RightBottom();
	
	half.x = half.x / 2;
	itmRect.SetRightBottom(half);
	
	// Command Keys
	fLeftCommand = new BamKeysKeyView(itmRect, "leftCommand", B_LEFT_COMMAND_KEY, B_FOLLOW_TOP | B_FOLLOW_LEFT);
	fSettingBox->AddChild(fLeftCommand);
	itmRect.OffsetBy((itmRect.Width() + 5), 0);
	
	fRightCommand = new BamKeysKeyView(itmRect, "rightCommand", B_RIGHT_COMMAND_KEY, B_FOLLOW_TOP | B_FOLLOW_LEFT);
	fSettingBox->AddChild(fRightCommand);
	itmRect.OffsetBy(-(itmRect.Width() + 5), itmRect.Height());
	
	// Ctrl Keys
	fLeftControl = new BamKeysKeyView(itmRect, "leftControl", B_LEFT_CONTROL_KEY, B_FOLLOW_TOP | B_FOLLOW_LEFT);
	fSettingBox->AddChild(fLeftControl);
	itmRect.OffsetBy((itmRect.Width() + 5), 0);
	
	fRightControl = new BamKeysKeyView(itmRect, "rightControl", B_RIGHT_CONTROL_KEY, B_FOLLOW_TOP | B_FOLLOW_LEFT);
	fSettingBox->AddChild(fRightControl);
	itmRect.OffsetBy(-(itmRect.Width() + 5), itmRect.Height());
	
	// Option Keys
	fLeftOption = new BamKeysKeyView(itmRect, "leftOption", B_LEFT_OPTION_KEY, B_FOLLOW_TOP | B_FOLLOW_LEFT);
	fSettingBox->AddChild(fLeftOption);
	itmRect.OffsetBy((itmRect.Width() + 5), 0);
	
	fRightOption = new BamKeysKeyView(itmRect, "rightOption", B_RIGHT_OPTION_KEY, B_FOLLOW_TOP | B_FOLLOW_LEFT);
	fSettingBox->AddChild(fRightOption);
	itmRect.OffsetBy(-(itmRect.Width() + 5), itmRect.Height());
	
	// Shift Keys
	fLeftShift = new BamKeysKeyView(itmRect, "leftShift", B_LEFT_SHIFT_KEY, B_FOLLOW_TOP | B_FOLLOW_LEFT);
	fSettingBox->AddChild(fLeftShift);
	itmRect.OffsetBy((itmRect.Width() + 5), 0);
	
	fRightShift = new BamKeysKeyView(itmRect, "rightShift", B_RIGHT_SHIFT_KEY, B_FOLLOW_TOP | B_FOLLOW_LEFT);
	fSettingBox->AddChild(fRightShift);
	itmRect.OffsetBy(-(itmRect.Width() + 5), itmRect.Height());
	
	
	// Buttons that do things!
	fBtnDefaults = new BButton(BRect(10, HEIGHT - 35, 85, HEIGHT - 15), 
							"btn_defaults", "Defaults", new BMessage('deft'),
							B_FOLLOW_BOTTOM | B_FOLLOW_LEFT);
	fBtnRevert = new BButton(BRect(95, HEIGHT - 35, 170, HEIGHT - 15),
							"btn_revert", "Revert", new BMessage('revt'),
							B_FOLLOW_BOTTOM | B_FOLLOW_LEFT);
	
	fRootView->AddChild(fScreenBox);
	fRootView->AddChild(fSettingBox, fScreenBox);
	fRootView->AddChild(fBtnDefaults, fSettingBox);
	fRootView->AddChild(fBtnRevert, fBtnDefaults);
	
	// If the fGrid couldn't load it settings, force our applications' defaults.
	if (fGrid->InitCheck() != B_OK) {
		BMessage *defaults = new BMessage('deft');
		MessageReceived(defaults);
		fGrid->SaveSettings();
		delete defaults;
		fModified = false;
	}
	fBtnRevert->SetEnabled(fModified);
}
示例#12
0
int main(void)
{
   struct tm *newtime;
   time_t ltime; 
   time(&ltime);                 /* Get the time in seconds */
   newtime = localtime(&ltime);  /* Convert it to the structure tm */
   char * st;            // gen purpose string for bcd's
   st = new char[35];   // 32 digits + sign + decimal pt + '\0'
 ofstream dout("bcdrun.log");
   bcd numa("1234567890987654.123");  // fraction will be dropped
   bcd numb(4321.6789);               // ditto - we are using integer rules
   bcd numc(-24681357L);
   bcd numd = numa + numb;
   bcd e(0.0);
   bcd f(0L);
   bcd g(-0.0);
   bcd h(-0L);
   bcd w(1L);
   bcd x(-1.0);
   bcd y("-2.0");
   bcd z("300.");
   bcd aa("99999999999999999999999999999999");
   bcd bb("1");
   bcd cc("10000000000000000");
   bcd dd(".00000000000000001");
   bcd m1(12L);
   bcd m2(2L);
   bcd m3(123456789L);
   bcd m4(4096L);
   bcd m5(748345987654321.0);
   bcd m6(288834570200345.0);
   bcd m7("8599238847786248452455563809");
   bcd d1("8765432109876");
   bcd d2(24687L);
   bcd d3(75237L);
   bcd d4(45263L);
   bcd d5 ("92732081006447");
   bcd s1("1234567890987654");

   dout << "                 Regression Log for " << asctime(newtime) << endl;

   dout << "significant digits test: 1 = " << w.sigD() << ", 3 = " << z.sigD()
        << ", 32 = " << aa.sigD() << ", 0 = " << dd.sigD() << "\n" << endl;

   int rc = numa.bcdToString(st); // convert numa to string no decimal point
   dout << "bcd to string test = " << st << "\n"
        << "          expected:  +1234567890987654" << endl;
   rc = numa.bcdToString(st,1);   // numa to str with 1 psn to right of dec pt
   dout << "bcd to string test = " << st << "\n"
        << "          expected:  +123456789098765.4" << endl;
   rc = numa.bcdToString(st,6);   // numa to str with 6 psns to rt of decimal pt
   dout << "bcd to string test = " << st << "\n"
        << "          expected:  +1234567890.987654" << "\n" << endl;

   rc = m3.bcdToString(st); // convert m3 to string no decimal point
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +123456789" << endl;
   rc = m3.bcdToString(st,1);   // m3 to str with 1 psn to right of dec pt
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +12345678.9" << endl;
   rc = m3.bcdToString(st,6);   // m3 to str with 6 psns to rt of decimal pt
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +123.456789" << "\n" << endl;

   rc = h.bcdToString(st); // convert h to string no decimal point
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +0" << endl;
   rc = h.bcdToString(st,1);   // convert h to str with 1 psn to right of dec pt
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +0.0" << endl;
   rc = h.bcdToString(st,6);   // h to str with 6 psns to rt of decimal pt
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +0.0" << "\n" << endl;

   rc = m2.bcdToString(st); // convert m2 to string no decimal point
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +2" << endl;
   rc = m2.bcdToString(st,1);   // m2 to str with 1 psn to right of dec pt
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +0.2" << endl;
   rc = m2.bcdToString(st,6);   // m2 to str with 6 psns to rt of decimal pt
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +0.000002" << "\n" << endl;

   s1.shl(1);
   dout << "shift test 1234567890987654 shifted left 1 = " << s1 
        << "   expected                                = +00000000000000012345678909876540 cc: 0\n" << endl;
   s1.shl(2);
   dout << "shift test 1234567890987654 shifted left 2 = " << s1 
        << "   expected                                = +00000000000001234567890987654000 cc: 0\n" << endl;
   s1.shl(3);
   dout << "shift test 1234567890987654 shifted left 3 = " << s1 
        << "   expected                                = +00000000001234567890987654000000 cc: 0\n" << endl;
   s1.shl(13);
   dout << "shift test 1234567890987654 shfted left 13 = " << s1 
        << "   expected                                = +00000000001234567890987654000000 cc: 16\n" << endl;
   s1.shr(1);
   dout << "shift test 1234567890987654 shifted rt 1 = " << s1 
        << "   expected                              = +00000000000123456789098765400000 cc: 0\n" << endl;
   s1.shr(2);
   dout << "shift test 1234567890987654 shifted rt 2 = " << s1 
        << "   expected                              = +00000000000001234567890987654000 cc: 0\n" << endl;
   s1.shr(5);
   dout << "shift test 1234567890987654 shifted rt 5 = " << s1 
        << "   expected                              = +00000000000000000012345678909876 cc: 0\n" << endl;
   s1.shrRnd(4);
   dout << "shift test 12345678909876 sh rt 4 & rnd  = " << s1
        << "   expected                              = +00000000000000000000001234567891 cc: 0\n" << endl;
   s1.shrRnd(4);
   dout << "shift test 12345678909876 sh rt 4 & rnd  = " << s1
        << "   expected                              = +00000000000000000000000000123457 cc: 0\n" << endl;
   s1.shrRnd(5);
   dout << "shift test 12345678909876 sh rt 5 & rnd  = " << s1
        << "   expected                              = +00000000000000000000000000000001 cc: 0\n" << endl;
   s1.shl(31);
   dout << "shift test 12345678909876 sh lt 31       = " << s1
        << "   expected                              = +10000000000000000000000000000000 cc: 0\n" << endl;

   bcd s2("1234567890987654321");
   s2.shrCpld(s1,6);               // odd shift even
   dout << "coupled shift s2 > s1,   s1 = " << s1
        << "                expected s1 = +00000000000000000000000000654321 cc: 0\n"
        << "                         s2 = " << s2
        << "                expected s2 = +00000000000000000001234567890987 cc: 0\n" << endl;
   s2.shrCpld(s1,5);               // odd shift odd
   dout << "coupled shift s2 > s1,   s1 = " << s1
        << "                expected s1 = +00000000000000000000000000090987 cc: 0\n"
        << "                         s2 = " << s2
        << "                expected s2 = +00000000000000000000000012345678 cc: 0\n" << endl;
   s2.shrCpld(s1,4);               // even shift even
   dout << "coupled shift s2 > s1,   s1 = " << s1
        << "                expected s1 = +00000000000000000000000000005678 cc: 0\n"
        << "                         s2 = " << s2
        << "                expected s2 = +00000000000000000000000000001234 cc: 0\n" << endl;
   s2.shrCpld(s1,3);               // odd shift odd
   dout << "coupled shift s2 > s1,   s1 = " << s1
        << "                expected s1 = +00000000000000000000000000000234 cc: 0\n"
        << "                         s2 = " << s2
        << "                expected s2 = +00000000000000000000000000000001 cc: 0\n" << endl;

   dout << "logical test 1 < 2   = " << int(bb<m2) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 1 > 2   = " << int(bb>m2) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 1 = 2   = " << int(bb==m2) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 2 < 1   = " << int(m2<bb) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 2 > 1   = " << int(m2>bb) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 2 = 1   = " << int(m2==bb) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 1 < 12  = " << int(bb<m1) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 1 > 12  = " << int(bb>m1) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 1 = 12  = " << int(bb==m1) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 12 < 1  = " << int(m1<bb) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 12 > 1  = " << int(m1>bb) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 12 = 1  = " << int(m1==bb) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test -1 < 2  = " << int(x<m2) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test -1 > 2  = " << int(x>m2) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test -1 = 2  = " << int(x==m2) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 2 < -1  = " << int(m2<x) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test -1 != 2  = " << int(x!=m2) << "\n"
        << "expected              = 1 \n" << endl;
   dout << "logical test 2 != -1  = " << int(m2!=x) << "\n"
        << "expected              = 1 \n" << endl;
   dout << "logical test 2 != 2   = " << int(m2!=m2) << "\n"
        << "expected              = 0 \n" << endl;
   dout << "logical test 2 > -1  = " << int(m2>x) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 2 = -1  = " << int(m2==x) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test d1 = d1 = " << int(d1==d1) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 0 = -0  = " << int(f==h) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test -0 = 0  = " << int(h==f) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 0 = 0   = " << int(f==f) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test -0 = -0 = " << int(h==h) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "divide test 8765432109876/24687 = " << d1/d2
        << "expected                        = +00000000000000000000000355062669 cc: 0\n" << endl;
   dout << "divide tst 92732081006447/45263 = " << d5/d4
        << "expected                        = +00000000000000000000002048739169 cc: 0\n" << endl;
   dout << "divide test 8765432109876/75237 = " << d1/d3
        << "expected                        = +00000000000000000000000116504274 cc: 0\n" << endl;
   dout << "divide test 1/24687             = " << bb/d2
        << "expected                        = +00000000000000000000000000000000 cc: 0\n" << endl;
   dout << "   test 10000000000000000/24687 = " << cc/d2
        << "expected                        = +00000000000000000000405071495118 cc: 0\n" << endl;
   dout << "   test 10000000000000000/3     = " << cc/3L
        << "expected                        = +00000000000000003333333333333333 cc: 0\n" << endl;
   dout << "   test 10000000000000000/6     = " << cc/6L
        << "expected                        = +00000000000000001666666666666666 cc: 0\n" << endl;
   dout << "   test 10000000000000000/7     = " << cc/7L
        << "expected                        = +00000000000000001428571428571428 cc: 0\n" << endl;
   dout << " div test 22000000000000000/7   = " << (cc*22L)/7L
        << "expected                        = +00000000000000031428571428571428 cc: 0\n" << endl;
   dout << "modulus test 24687%1000         = " << d2%1000L
        << "expected                        = +00000000000000000000000000000687 cc: 0\n" << endl;
   dout << "divide by zero test 75237/0     = " << d3/0L
        << "expected                        = +00000000000000000000000000075237 cc: 16\n" << endl;
   dout << "divide d1/d1 test               = " << d1/d1
        << "expected                        = +00000000000000000000000000000001 cc: 0\n" << endl;
   dout << "re-subtract test: 12345 - 12346 = " << bcd(12345L) - 12346L
        << "expected                        = -00000000000000000000000000000001 cc: 0\n"
        << " reverse opnds:   12346 - 12345 = " << bcd(12346L) - 12345L
        << "expected                        = +00000000000000000000000000000001 cc: 0\n" << endl;
   dout << "8599238847786248452455563809*45263       = " << m7 * d4
        << "                               expected:   +00008599238847786248452455563809 cc: 15\n" << endl;
   dout << "748345987654321 x 288834570200345        = " << m5 * m6
        << "                               expected:   +00216148191705288491573574940745 cc: 0\n" << endl;
   dout << "748345987654321 x 288834570200345 x 10   = " << m5 * m6 * 10.0
        << "                               expected:   +02161481917052884915735749407450 cc: 0\n" << endl;
   dout << "748345987654321 x 288834570200345 x 100  = " << m5 * m6 * 100.0
        << "                               expected:   +21614819170528849157357494074500 cc: 0\n" << endl;
   dout << "748345987654321 x 288834570200345 x 1000 = " << m5 * m6 * 1000.0
        << "                               expected:   +00216148191705288491573574940745 cc: 16\n" << endl;
   dout << "123456789 x 123456789 x 123456789        = " << m3 * m3 * m3
        << "                               expected:   +00000001881676371789154860897069 cc: 0\n" << endl;
   dout << "123456789 x 123456789 x 123456789 x 123456789 = " << m3 * m3 * m3 * m3
        << "                                    expected:   +00000001881676371789154860897069 cc: 16\n" << endl;
   dout << "                                        2 x 2 = " << m2*m2
        << "                                    expected:   +00000000000000000000000000000004 cc: 0\n" << endl;
   dout << "                                       2 x 12 = " << m2*m1
        << "                                    expected:   +00000000000000000000000000000024 cc: 0\n" << endl;
   dout << "                                2 x 123456789 = " << m2 * m3
        << "                                    expected:   +00000000000000000000000246913578 cc: 0\n" << endl;
   dout << "                                123456789 x 2 = " << m3 * m2
        << "                                    expected:   +00000000000000000000000246913578 cc: 0\n" << endl;
   dout << " 4096 x 2 = " << m4 * m2
        << "expected:   +00000000000000000000000000008192 cc: 0\n" << endl;
   dout << " 2 x 4096 = " << m2 * m4
        << "expected:   +00000000000000000000000000008192 cc: 0\n" << endl;
   dout << " 2 x 12 x 4096 = " << m2 * m1 * m4
        << "expected:        +00000000000000000000000000098304 cc: 0\n" << endl;
   dout << "    aa = " << aa
        << "    bb = " << bb
        << " aa-bb = " << aa-bb
        << "expected:+99999999999999999999999999999998 cc: 0\n"
        << " aa+bb = " << aa+bb 
        << "expected:+00000000000000000000000000000000 cc: 1\n" << endl;
   dout << "     e = " << e
        << "     f = " << f
        << " e + f = " << e+f
        << "expected:+00000000000000000000000000000000 cc: 0\n" 
        << " e - f = " << e-f 
        << "expected:+00000000000000000000000000000000 cc: 0\n" << endl;
   dout << "     g = " << g
        << "     h = " << h
        << " g + h = " << g+h
        << "expected:+00000000000000000000000000000000 cc: 0\n"
        << " g - h = " << g-h 
        << "expected:+00000000000000000000000000000000 cc: 0\n" << endl;
   dout << "     w = " << w
        << "     x = " << x
        << " w + x = " << w+x
        << "expected:+00000000000000000000000000000000 cc: 0\n"
        << " w - x = " << w-x 
        << "expected:+00000000000000000000000000000002 cc: 0\n" << endl;
   dout << "     y = " << y
        << "     z = " << z
        << " y + z = " << y+z
        << "expected:+00000000000000000000000000000298 cc: 0\n"
        << " y - z = " << y-z 
        << "expected:-00000000000000000000000000000302 cc: 0\n" << endl;
   dout << "numa =      " << numa 
        << "numb =      " << numb
        << "numa+numb = " << numd
        << "expected:   +00000000000000001234567890991975 cc: 0\n"
        << "numb+numa = " << numb+numa 
        << "expected:   +00000000000000001234567890991975 cc: 0\n" << endl;
   dout << "numa =      " << numa 
        << "numc =      " << numc
        << "numa+numc = " << numa+numc 
        << "expected:   +00000000000000001234567866306297 cc: 0\n"
        << "numc+numa = " << numc+numa
        << "expected:   +00000000000000001234567866306297 cc: 0\n" << endl;
   dout << "numb =      " << numb
        << "numc =      " << numc
        << "numb+numc = " << numb+numc 
        << "expected:   -00000000000000000000000024677036 cc: 0\n"
        << "numc+numb = " << numc+numb 
        << "expected:   -00000000000000000000000024677036 cc: 0\n" << endl;
   dout << "numa =      " << numa 
        << "numb =      " << numb
        << "numa-numb = " << numa-numb 
        << "expected:   +00000000000000001234567890983333 cc: 0\n" 
        << "numb-numa = " << numb-numa 
        << "expected:   -00000000000000001234567890983333 cc: 0\n" << endl;
   dout << "numa =      " << numa 
        << "numc =      " << numc
        << "numa-numc = " << numa-numc 
        << "expected:   +00000000000000001234567915669011 cc: 0\n"
        << "numc-numa = " << numc-numa 
        << "expected:   -00000000000000001234567915669011 cc: 0\n" << endl;
   dout << "numb =      " << numb
        << "numc =      " << numc
        << "numb-numc = " << numb-numc 
        << "expected:   +00000000000000000000000024685678 cc: 0\n"
        << "numc-numb = " << numc-numb
        << "expected:   -00000000000000000000000024685678 cc: 0\n" << endl;
   dout.close();
   delete st;
   return 0;
}