array shifter
#11
To use this practically you would have to put it in a header file, something like in C. For example: <numeric.h>. And in the program one access it via "_bignumberXY".

But there are also "everyday" problems with decimal numbers. See screenshot: QB64 above, then in C, Win-Calculator, and then in C in Linux (well, it's just the same GCC).
The question is, which result is correct in practice? So the back calculation.


In QB64 - 3.2
Code: (Select All)
Option _Explicit

Declare Function Nte_Wurzel(n As Double, x As Double) As Double
Declare Function Nte_Potenz(n As Double, x As Double) As Double

Dim As Double n, x

Print
Input "Wurzelexponent: ", n
Input "Radikand      : ", x

Print
Print Using "Die ###.## Wurzel aus ###.## ist: ##.##########"; n, x, Nte_Wurzel(n, x)
Print: Print
Print "Ueberpruefung: Wurzelwert mit demselben Exponenten potenzieren"
Print
Print Using "Wurzelwert ##.########## potenziert mit Exponent ###.## ergibt: ##.######"; Nte_Wurzel(n, x), n, Nte_Potenz(Nte_Wurzel(n, x), n)

End

Function Nte_Wurzel (n As Double, x As Double)

  Dim wurzelx As Double

  wurzelx = x ^ (1 / n)
  Nte_Wurzel = wurzelx
End Function

Function Nte_Potenz (wurzelx As Double, exponent As Double)

  Dim potenz As Double

  potenz = wurzelx ^ exponent
  Nte_Potenz = potenz
End Function

In C 
Code: (Select All)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

double nte_wurzel(double n, double x);
double nte_potenz(double n, double x);

int main(void)
{
    double n, x;      //n = Wurzelexponent, x = Radikand
        
    printf("\nBerechnung der n-ten Wurzel");
    printf("\nWurzelexponent: ");
    scanf("%lf", &n);
    printf("Radikand      : ");
    scanf("%lf", &x);
        
    printf("\n\nDie %5.2f Wurzel aus %5.2f = %12.10f", n, x, nte_wurzel(n, x));
    printf("\nWurzelwert %12.10f potenziert mit Exponent %5.2f ergibt: %9.6f", nte_wurzel(n, x), n, nte_potenz(nte_wurzel(n, x), n));
    
    return(0);
}

double nte_wurzel(double n, double x)
{
    double wurzelx;
    
    wurzelx = pow(x, (1.0 / n));
    return(wurzelx);
}

double nte_potenz(double n, double x)
{
    double potenz;
    
    potenz = pow(n, x);
    return(potenz);
}

[Image: Runden-in-QB64-C-2022-09-22.jpg]
Reply
#12
I spent almost all day trying to port my binary math routines to QB64 but it's impossible, so I am rewriting it as a C include, so far so good.
the reason it's impossible is because the routines use the full 32-bits of the Long and trying to do comparisons is unworkable, believe me I tried
Reply
#13
I still don't know for what purpose you'd need such precision. Are we building rockets to the moon?
Ask me about Windows API and maybe some Linux stuff
Reply
#14
(09-23-2022, 02:56 PM)Spriggsy Wrote: I still don't know for what purpose you'd need such precision. Are we building rockets to the moon?

Well certainly not our moon. Moons in the Alpha Centauri star system, well, now you're getting closer.

Pi calculations, and probably some other math problems to solve, or to approximate, need a better mouse trap than DOUBLE, etc. provide.

String math, what Jack is doing with bit shifting, etc. are all valid, interesting, albeit, very involved ways of avoiding DOUBLE trouble.

Pete
Reply
#15
Spriggsy, it's only for the challenge, for me numbers are an interesting pastime
Reply
#16
"Only for the challenge." You mean I won't be vacationing on Risa anytime soon? Dammit!

Pete
Reply




Users browsing this thread: 3 Guest(s)