PageRenderTime 34ms CodeModel.GetById 24ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/cln-1.3.2/src/rational/input/cl_RA_readparsed.cc

#
C++ | 32 lines | 20 code | 8 blank | 4 comment | 3 complexity | d6b7ed645c6c55dfb653ce25500a7648 MD5 | raw file
Possible License(s): GPL-2.0
 1// read_rational().
 2
 3// General includes.
 4#include "base/cl_sysdep.h"
 5
 6// Specification.
 7#include "cln/rational_io.h"
 8
 9
10// Implementation.
11
12#include "rational/cl_RA.h"
13#include "integer/cl_I.h"
14#include "base/cl_N.h"
15
16namespace cln {
17
18const cl_RA read_rational (unsigned int base, cl_signean sign, const char * string, uintC index1, uintC index3, uintC index2)
19{
20	var uintC index3_1 = index3+1; // Index der ersten Nennerziffer
21	var cl_I den = // Nenner
22	  digits_to_I(&string[index3_1],index2-index3_1,(uintD)base);
23	if (zerop(den)) // Division durch 0 abfangen
24		{ throw division_by_0_exception(); }
25	var cl_I num = // Z?hler
26	  digits_to_I(&string[index1],index3-index1,(uintD)base);
27	if (!(sign == 0))
28		num = -num; // incl. Vorzeichen
29	return I_posI_div_RA(num,den);
30}
31
32}  // namespace cln