vnl_io_rational.cxx
Go to the documentation of this file.
1 // This is core/vnl/io/vnl_io_rational.cxx
2 //:
3 // \file
4 
5 #include "vnl_io_rational.h"
6 #include <vsl/vsl_binary_io.h>
7 
8 //=================================================================================
9 //: Binary save self to stream.
10 void vsl_b_write(vsl_b_ostream & os, const vnl_rational & p)
11 {
12  constexpr short io_version_no = 1;
13  vsl_b_write(os, io_version_no);
14  vsl_b_write(os, p.numerator());
15  vsl_b_write(os, p.denominator());
16 }
17 
18 //=================================================================================
19 //: Binary load self from stream.
20 void vsl_b_read(vsl_b_istream &is, vnl_rational & p)
21 {
22  if (!is) return;
23  short ver;
24  long n, d;
25  vsl_b_read(is, ver);
26  switch (ver)
27  {
28  case 1:
29  vsl_b_read(is, n);
30  vsl_b_read(is, d);
31  p.set(n,d);
32  break;
33 
34  default:
35  std::cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vnl_rational&)\n"
36  << " Unknown version number "<< ver << '\n';
37  is.is().clear(std::ios::badbit); // Set an unrecoverable IO error on stream
38  return;
39  }
40 }
41 
42 //====================================================================================
43 //: Output a human readable summary to the stream
44 void vsl_print_summary(std::ostream & os,const vnl_rational & p)
45 {
46  os<<p;
47 }
void set(long num, long den)
Definition: vnl_rational.h:130
void vsl_print_summary(std::ostream &os, vnl_bignum const &b)
Print human readable summary of object to a stream.
void vsl_b_read(vsl_b_istream &is, vnl_bignum &v)
Binary load vnl_bignum from stream.
void vsl_b_write(vsl_b_ostream &os, vnl_bignum const &v)
Binary save vnl_bignum to stream.
long numerator() const
Return the numerator of the (simplified) rational number representation.
Definition: vnl_rational.h:133
long denominator() const
Return the denominator of the (simplified) rational number representation.
Definition: vnl_rational.h:135
High-precision rational numbers.
Definition: vnl_rational.h:73