Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Limitation of function EXP()
#1
Why is in QB64 a limitation of the function EXP ?

        "EXP(numericExpression)
          ...
         The numericExpression must be less than or equal to 88.02969 or an "overflow" error will occur."

In C a similar limitation is much higher.

(I need it to use the Planck's law to calculate the spectral density of the electromagnetic radiation at low temperatures.)

With my C program the Planck's law can be applied at a temperature of 1K, in QB64 not lower than 102 K!
Reply
#2
To cure yourself, you could import the function from C++:

https://qb64phoenix.com/qb64wiki/index.p...s_and_Subs

Discover which one you want and prototype it surrounding it with "DECLARE LIBRARY... END DECLARE" block.

"EXP()" in QB64(PE) isn't going to be changed because it was part of the behavior of QuickBASIC and QBasic.
Reply
#3
@BSpinoza
I think that the Exp function in QB64 supports _Float, but remember that print only supports double
you may be able to do your calculation using _Float
Reply
#4
(02-22-2023, 11:26 AM)BSpinoza Wrote: Why is in QB64 a limitation of the function EXP ?

        "EXP(numericExpression)
          ...
         The numericExpression must be less than or equal to 88.02969 or an "overflow" error will occur."

In C a similar limitation is much higher.

(I need it to use the Planck's law to calculate the spectral density of the electromagnetic radiation at low temperatures.)

With my C program the Planck's law can be applied at a temperature of 1K, in QB64 not lower than 102 K!

Good question. Say, can you do the whole calculation in log space rather than using the exp function? We do this a lot in statistical mechanics. Spill the math here if you want, I'll get there with you if its possible.
Reply
#5
(02-22-2023, 11:26 AM)BSpinoza Wrote: Why is in QB64 a limitation of the function EXP ?

        "EXP(numericExpression)
          ...
         The numericExpression must be less than or equal to 88.02969 or an "overflow" error will occur."

I don't get an error message. Or what am I doing wrong?
Code: (Select All)
Option _Explicit

Dim As Double resultat, exponent

exponent = 98.02969

resultat = Exp(exponent)

Print resultat

End
Reply
#6
Looks to me like QB64 can handle values larger than 88...

Code: (Select All)
// EXP
double func_exp_single(double value) {
    if (value <= 88.02969) {
        return exp(value);
    }
    error(6);
    return 0;
}
long double func_exp_float(long double value) {
    if (value <= 709.782712893) {
        return exp(value);
    }
    error(6);
    return 0;
}


There's our EXP functions.  If you pass it a single, it needs a value of 88 or less.  Pass it a double/float, and it works with a value < 709.

   
Reply
#7
Yes, an integer causes an error.

[Image: EXP-Uebung-Int2023-02-22.jpg]
Reply
#8
(02-22-2023, 12:22 PM)Jack Wrote: @BSpinoza
I think that the Exp function in QB64 supports _Float, but remember that print only supports double
you may be able to do your calculation using _Float

I was wrong, QB64 exp function treats _Float as double, however you can use the C function expl
Code: (Select All)
Declare CustomType Library
    Function expl## (ByVal x As _Float)
End Declare

Dim As _Float x, y
x = 11354##
y = expl(x)
Print y
<< edit >>
forgot that the print statement does not support _Float, (it does in my modified version)
nevertheless, if the end result is within range of double you can use expl
Reply
#9
It seems to be a problem of the number type!

This is working:


Code: (Select All)
DIM I AS _FLOAT
FOR I = 1 TO 200 STEP 1
  PRINT I, EXP(I)
NEXT


If you remove the DIM statement, it stops at 88.
Thanks to all for your answers!
Reply
#10
without the dim statement it defaults to single, you don't need _Float only double as the exp function maximum precision is double
Reply




Users browsing this thread: 1 Guest(s)