[CLN-list] confusion with cln::cl_F and cln::cl_R

Alexei Sheplyakov alexei.sheplyakov at gmail.com
Tue May 18 22:37:49 CEST 2010


On Tue, May 18, 2010 at 11:22:25AM -0400, Joshua Friedman wrote:
> The program runs when I define "bigF = cln_R", but I get errors when I set
> "bigF = cln_F"
> I found that the exponential function only gives many digits of precision
> when I use cln_F.
> I am attaching my program and the out put is below:

Here's a simpler example which illustrates the problem.

$ cat noconv.cc

#include <cln/cln.h>

cln::cl_F foo(const cln::cl_F& x) 
	cln::cl_F one = 1; 
	return one; 

This code won't compile because CLN does not provide implicit conversion
of exact numbers (such as integers) into inexact ones (i.e. floating
point ones):

g++ -c noconv.cc  `pkg-config --libs --cflags cln`
noconv.cc: In function ‘cln::cl_F foo(const cln::cl_F&)’:
noconv.cc:5: error: conversion from ‘int’ to ‘cln::cl_F’ is ambiguous
/home/varg/target/x86_64-linux-gnu/include/cln/float_class.h:38: note: candidates are: cln::cl_F::cl_F(cln::cl_anything*) <near match>
/home/varg/target/x86_64-linux-gnu/include/cln/float_class.h:26: note:                 cln::cl_F::cl_F(const char*) <near match>
/home/varg/target/x86_64-linux-gnu/include/cln/float_class.h:48: note:                 cln::cl_F::cl_F(double)
/home/varg/target/x86_64-linux-gnu/include/cln/float_class.h:47: note:                 cln::cl_F::cl_F(float)

One should use an appropriate cl_float function, i.e.

#include <cln/cln.h>

cln::cl_F foo(const cln::cl_F& x)
	cln::cl_F one = cln::cl_float(1, x);
	// Constructs a floating-point number representing 1 with the same
	// mantissa size as that of x
	return one;

I admit this is a bit annoying, but debugging issues due to implicit
conversions is even more annoying.

Best regards,

More information about the CLN-list mailing list