aboutsummaryrefslogtreecommitdiff
path: root/float2rat.c
diff options
context:
space:
mode:
Diffstat (limited to 'float2rat.c')
-rw-r--r--float2rat.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/float2rat.c b/float2rat.c
new file mode 100644
index 0000000..1b44a96
--- /dev/null
+++ b/float2rat.c
@@ -0,0 +1,87 @@
+/*
+ * Reads a polyhedron file on stdin with rationals and outputs
+ * an approximation in decimal floating point
+ *
+ * David Bremner. bremner@cs.mcgill.ca
+ *
+ */
+
+static char rcsid[]="$Id$";
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <float.h>
+
+#include "float2rat.ds"
+
+main(argc,argv)
+ int argc;
+ char **argv;
+{
+ long int m,n;
+ int i,j;
+
+ long atol();
+
+ long **N;
+ long **D;
+
+ char buf[BUFSIZ];
+
+ CHECK_HELP;
+
+ while ( fgets(buf,BUFSIZ,stdin) !=NULL )
+ {
+ fputs(buf,stdout);
+ if (strncmp(buf,"begin",5)==0) break;
+ }
+
+
+ if (scanf("%ld %ld %s",&m,&n,buf)==EOF){
+ fprintf(stderr,"No begin line");
+ exit(1);
+ }
+
+ printf("%ld %ld rational\n",m,n);
+
+
+ for (i=0;i<m;i++) {
+ for(j=0;j<n;j++) {
+ char *p;
+ char *frac;
+ int k;
+
+ scanf("%s",buf);
+
+ if (p=index(buf,'.')){
+ *p=0;
+ frac=&p[1];
+ } else {
+ frac="";
+ }
+
+
+ printf("%s%s/1",buf,frac);
+ for (k=0; k<strlen(frac); k++)
+ putchar('0');
+
+ putchar(' ');
+
+ }
+ fputs("\n",stdout);
+ }
+
+ fgets(buf,BUFSIZ,stdin); /* clean off last line */
+
+ while (fgets(buf,BUFSIZ,stdin) !=NULL )
+ {
+ fputs(buf,stdout);
+ }
+}
+
+
+
+
+
+