When certain arguments of the frexp, ldexp, scalbn, and remquo functions in math.h are of the int type, compiling the C++ or EC++ program generates object code that will enter an endless loop.
This problem occurs when both (1) and (2) are satisfied.
frexp(double, long*) with 'int *' type second argument (except when the first argument is float-type and the |
lldexp(double, long) with int type second argument (except when the first argument is float-type and the |
scalbn(double, long) with int type second argument (except when the first argument is float-type and the |
remquo(double, double, long*) with 'int *' type third argument (except when the both the first and second |
// Example of compiling C++ source that generates an endless loop
#include <math.h>
double d1,d2;
int i;
void func(void)
{
d2 = frexp(d1, &i);
}
ccrx -cpu=rx600 -output=src file.cpp
file.src: Example of the generated assembly program
_func:
; ...(Omitted)
; Calling substitute function of frexp
BSR __$frexp__tm__2_f__FZ1ZPi_Q2_21_Real_type__tm__4_Z1Z5_Type
; ...(Omitted)
__$frexp__tm__2_f__FZ1ZPi_Q2_21_Real_type__tm__4_Z1Z5_Type:
L11:
BRA L11 ; Calls itself ==> endless loop
Select one of the following ways to avoid the problem.
/* For the frexp function */
static inline double frexp(double x, int *y)
{ long v = *y; double d = frexp(x,&v); *y = v; return (d); }
/* For the ldexp function */
static inline double ldexp(double x, int y)
{ long v = y; double d = ldexp(x,v); return (d); }
/* For the scalbn function */
static inline double scalbn(double x, int y)
{ long v = y; double d = scalbn(x,v); return (d); }
/* For the remquo function */
static inline double remquo(double x, double y, int *z)
{ long v = *z; double d = remquo(x,y,&v); *z = v; return (d); }
#include <math.h>
double d1,d2;
int i;
void func(void)
{
long x = i; /* Accept as long type temporary */
d2 = frexp(d1, &x); /* Call with long type argument */
i = x; /* Set the result for variable 'i' */
}
#include <math.h>
/* Append declaration */
static inline double frexp(double x, int *y)
{ long v = *y; double d = frexp(x,&v); *y = v; return (d); }
double d1,d2;
int i;
void func(void)
{
d2 = frexp(d1, &i);
}