Example #1
0
File: float_t.c Project: pdo/aldor
void
testInteractive()
{
	FiSFlo  sfl, sfl0;
	FiDFlo  dfl, dfl0;
	FiSFlo	sfrac;
	FiDFlo  dfrac;
	BInt	bi;

	while (1) {

		printf("\nEnter a single float: ");
		IgnoreResult(scanf(SFLO_SFMT, &sfl));

		printf("\ntrunc(%.*g) = ", 9, sfl);

		bi = (BInt) fiSFloTruncate(sfl);
		bintPrint(osStdout, bi);

		sfrac = fiSFloFraction(sfl);
		printf("\nfrac = %g \n", sfrac);

		testSFloParts(sfl, bi, sfrac);

		sfl0 = fiSFloNext(sfl);
		printf("Next: %.*g (eq = %d)\n", 9, sfl0, sfl == sfl0);

		printf("\nEnter a double float: ");
		IgnoreResult(scanf("%lf", &dfl));

		printf("\ntrunc(%.*g) = ", 50, dfl);

		bi = (BInt) fiDFloTruncate(dfl);
		bintPrint(osStdout, bi);

		dfrac = fiDFloFraction(dfl);
		printf("\nfrac = %g \n", dfrac);

		testDFloParts(dfl, bi, dfrac);

		dfl0 = fiDFloNext(dfl);
		printf("Next: %.*g (diff = %.*g)\n", 50, dfl0, 50, dfl0 - dfl);

		/* for (i = 0; i < sizeof(FiDFlo) */
	}

}
Example #2
0
int
obPrint(FILE *fout, Pointer ob)
{
	if (!ob) return fprintf(fout, "OB_0");

	switch (obCode(ob)) {
	case OB_Bogus:	 bug("Bad object.");
	case OB_BTree:	 return btreePrint(fout, (BTree) ob);
	case OB_BInt:	 return bintPrint(fout,	 (BInt) ob);
	case OB_Bitv:	 return bitvPrint(fout, (BitvClass) NULL, (Bitv) ob);
	case OB_String:	 return strPrint(fout,	 (String) ob,
				'"', '"', '\\', "\\%#x");
	case OB_Buffer:	 return bufPrint(fout,	 (Buffer) ob);
	case OB_List:	 return listPrint(Pointer)(fout, (PointerList) ob,
				obPrint);
	case OB_Table:	 return tblPrint(fout, (Table) ob,
				(TblPrKeyFun) obPrint, (TblPrEltFun) obPrint);
	case OB_Symbol:	 return symPrint(fout, (Symbol) ob);
	case OB_SExpr:	 return sxiWrite(fout, (SExpr) ob, SXRW_Default);
	case OB_CCode:	 return ccoPrint(fout, (CCode) ob, CCOM_StandardC);
	case OB_JCode:	 return fprintf(fout, "java");

	case OB_SrcLine: return slinePrint(fout, (SrcLine) ob);
	case OB_Token:	 return tokPrint(fout, (Token) ob);
	case OB_Doc:	 return docPrint(fout, (Doc) ob);
	case OB_AbSyn:	 return abPrint(fout, (AbSyn) ob);
	case OB_Syme:	 return symePrint(fout, (Syme) ob);
	case OB_TForm:	 return tfPrint(fout, (TForm) ob);
	case OB_TPoss:	 return tpossPrint(fout, (TPoss) ob);
	case OB_TConst:	 return tcPrint(fout, (TConst) ob);
	case OB_TQual:	 return tqPrint(fout, (TQual) ob);
	case OB_Foam:	 return foamPrint(fout, (Foam) ob);

	case OB_Lib:
	case OB_Archive:
	default:	 return fprintf(fout, "%p->OB_%d", ob, obCode(ob));
	}
}