while I wasn't setting the length of the return qbs_str the bug of print using was not related to any of my code, try this example and see what you get
the latest QB64 git repo without any changes gives this
here are the modified qbs_str functions in case someone wants to try them out
Code: (Select All)
$Console:Only
_Dest _Console
Dim As _Float f
f = Factorial_Recursive(50)
Print Using "##.##################"; f
Print f
Function Factorial_Recursive## (n As Integer)
If n = 0 Then Factorial_Recursive## = 1: Exit Function
Factorial_Recursive## = n * Factorial_Recursive##(n - 1)
End Function
Quote:%30414093201713378039796484017234741538658648106343392576177963008.000000000000000000when I first saw that on my modded version I immediately blamed my meddling but that's not the case
3.041409320171338D+64
here are the modified qbs_str functions in case someone wants to try them out
Code: (Select All)
qbs *qbs_str(double value){
static qbs *tqbs;
tqbs=qbs_new(32,1);
static int32 l, i,j,digits,exponent;
#ifdef QB64_MINGW
__mingw_sprintf((char*)&qbs_str_buffer,"% .14Le",(long double) value);
#else
sprintf((char*)&qbs_str_buffer,"% .14Le",(long double) value);
#endif
exponent=atoi((char*)&qbs_str_buffer[18]);
digits=16;
while((qbs_str_buffer[digits]=='0')&&(digits>0)) digits--;
tqbs->chr[0]=qbs_str_buffer[0]; // copy sign
if(exponent==0){
for(i=1;i<=(digits);i++){
tqbs->chr[i]=qbs_str_buffer[i];
}
if(tqbs->chr[digits]=='.') // if no digits after . then nip it
tqbs->len=digits; // by zero terminating
else
tqbs->len=digits+1; // zero terminate
}
else if(exponent<0){
if((digits-exponent)>=19){ // use sci format
for(i=1;i<=digits;i++){
tqbs->chr[i]=qbs_str_buffer[i];
}
if(tqbs->chr[digits]=='.'){
tqbs->chr[digits]='D';
sprintf((char*)&tqbs->chr[digits+1],"%+03d", exponent);
l=digits+1;
while((tqbs->chr[l])!=0) l++;
tqbs->len=l;
}
else{
tqbs->chr[digits+1]='D';
sprintf((char*)&tqbs->chr[digits+2],"%+03d", exponent);
l=digits+2;
while((tqbs->chr[l])!=0) l++;
tqbs->len=l;
}
}
else{
tqbs->chr[1]='.';
for(i=2;i<=abs(exponent);i++){
tqbs->chr[i]='0';
}
tqbs->chr[abs(exponent)+1]=qbs_str_buffer[1]; // first non-zero digit
j=3; // skip decimal point
for(i=abs(exponent)+2;i<(abs(exponent)+digits);i++){
tqbs->chr[i]=qbs_str_buffer[j];
j++;
}
tqbs->len=abs(exponent)+digits; // zero terminate
}
}
else if(exponent>0){
if((digits<17)&&(exponent<15)){
tqbs->chr[1]=qbs_str_buffer[1]; // first digit
j=3; // skip over .
for(i=2;i<=(exponent+1);i++){
tqbs->chr[i]=qbs_str_buffer[j];
j++;
}
if((digits>exponent)&&(digits>(j-1))){
tqbs->chr[exponent+2]='.';
for(i=exponent+3;i<=(digits);i++){
tqbs->chr[i]=qbs_str_buffer[j];
j++;
}
tqbs->len=digits+1;
}
else{
tqbs->len=exponent+2;
}
}
else{
for(i=0;i<=digits;i++){
tqbs->chr[i]=qbs_str_buffer[i];
}
if(tqbs->chr[digits]=='.'){
tqbs->chr[digits]='D';
sprintf((char*)&tqbs->chr[digits+1],"%+03d", exponent);
l=digits+1;
while((tqbs->chr[l])!=0) l++;
tqbs->len=l;
}
else{
tqbs->chr[digits+1]='D';
sprintf((char*)&tqbs->chr[digits+2],"%+03d", exponent);
l=digits+2;
while((tqbs->chr[l])!=0) l++;
tqbs->len=l;
}
}
}
return tqbs;
}
qbs *qbs_str(long double value){
static qbs *tqbs;
tqbs=qbs_new(32,1);
static int32 l, i,j,digits,exponent;
#ifdef QB64_MINGW
__mingw_sprintf((char*)&qbs_str_buffer,"% .17Le", value);
#else
sprintf((char*)&qbs_str_buffer,"% .17Le", value);
#endif
exponent=atoi((char*)&qbs_str_buffer[21]);
digits=19;
while((qbs_str_buffer[digits]=='0')&&(digits>0)) digits--;
tqbs->chr[0]=qbs_str_buffer[0]; // copy sign
if(exponent==0){
for(i=1;i<=(digits);i++){
tqbs->chr[i]=qbs_str_buffer[i];
}
if(tqbs->chr[digits]=='.') // if no digits after . then nip it
tqbs->len=digits; // by zero terminating
else
tqbs->len=digits+1; // zero terminate
}
else if(exponent<0){
if((digits-exponent)>=22){ // use sci format
for(i=1;i<=digits;i++){
tqbs->chr[i]=qbs_str_buffer[i];
}
if(tqbs->chr[digits]=='.'){
tqbs->chr[digits]='F';
sprintf((char*)&tqbs->chr[digits+1],"%+03d", exponent);
l=digits+1;
while((tqbs->chr[l])!=0) l++;
tqbs->len=l;
}
else{
tqbs->chr[digits+1]='F';
sprintf((char*)&tqbs->chr[digits+2],"%+03d", exponent);
l=digits+2;
while((tqbs->chr[l])!=0) l++;
tqbs->len=l;
}
}
else{
tqbs->chr[1]='.';
for(i=2;i<=abs(exponent);i++){
tqbs->chr[i]='0';
}
tqbs->chr[abs(exponent)+1]=qbs_str_buffer[1]; // first non-zero digit
j=3; // skip decimal point
for(i=abs(exponent)+2;i<(abs(exponent)+digits);i++){
tqbs->chr[i]=qbs_str_buffer[j];
j++;
}
tqbs->len=abs(exponent)+digits; // zero terminate
}
}
else if(exponent>0){
if((digits<20)&&(exponent<18)){
tqbs->chr[1]=qbs_str_buffer[1]; // first digit
j=3; // skip over .
for(i=2;i<=(exponent+1);i++){
tqbs->chr[i]=qbs_str_buffer[j];
j++;
}
if((digits>exponent)&&(digits>(j-1))){
tqbs->chr[exponent+2]='.';
for(i=exponent+3;i<=(digits);i++){
tqbs->chr[i]=qbs_str_buffer[j];
j++;
}
tqbs->len=digits+1;
}
else{
tqbs->len=exponent+2;
}
}
else{
for(i=0;i<=digits;i++){
tqbs->chr[i]=qbs_str_buffer[i];
}
if(tqbs->chr[digits]=='.'){
tqbs->chr[digits]='F';
sprintf((char*)&tqbs->chr[digits+1],"%+03d", exponent);
l=digits+1;
while((tqbs->chr[l])!=0) l++;
tqbs->len=l;
}
else{
tqbs->chr[digits+1]='F';
sprintf((char*)&tqbs->chr[digits+2],"%+03d", exponent);
l=digits+2;
while((tqbs->chr[l])!=0) l++;
tqbs->len=l;
}
}
}
return tqbs;
}