Giter Club home page Giter Club logo

Comments (3)

baboomerang avatar baboomerang commented on May 24, 2024

The main reason for the truncation was because of a highlighted part of this code.
The built in library that handles all the Big-Numbers is truncating the whole exponent to a 32 bit integer.
Which isn't necessarily bad, but kind of absurd if you ask me because most, if not all floating point decimals are gone.

Revised log tables will be needed for all of this math to work. The Epsilon will have to be extended.
long floats are required. (in concept, but that wont actually be the case)

void
bc_raise (num1, num2, result, scale)
bc_num num1, num2, *result;
int scale;
{
bc_num temp, power;
long exponent;
int rscale;
int pwrscale;
int calcscale;
char neg;

_/ Check the exponent for scale digits and convert to a long. /
if (num2->n_scale != 0)
bc_rt_warn (BC_WARNING_NON_ZERO_SCALE_IN_EXPONENT);
exponent = bc_num2long (num2);
if (exponent == 0 && (num2->n_len > 1 || num2->n_value[0] != 0))
bc_rt_error (BC_ERROR_EXPONENT_TOO_LARGE_IN_RAISE);_

/* Special case if exponent is a zero. */
if (exponent == 0)
{
bc_free_num (result);
*result = bc_copy_num (one);
return;
}

/* Other initializations. /
if (exponent < 0)
{
neg = TRUE;
exponent = -exponent;
rscale = scale;
}
else
{
neg = FALSE;
rscale = MIN (num1->n_scale
exponent, MAX(scale, num1->n_scale));
}

/* Set initial value of temp. /
power = bc_copy_num (num1);
pwrscale = num1->n_scale;
while ((exponent & 1) == 0)
{
pwrscale = 2
pwrscale;
bc_multiply (power, power, &power, pwrscale);
exponent = exponent >> 1;
}
temp = bc_copy_num (power);
calcscale = pwrscale;
exponent = exponent >> 1;

/* Do the calculation. /
while (exponent > 0)
{
pwrscale = 2
pwrscale;
bc_multiply (power, power, &power, pwrscale);
if ((exponent & 1) == 1) {
calcscale = pwrscale + calcscale;
bc_multiply (temp, power, &temp, calcscale);
}
exponent = exponent >> 1;
}

/* Assign the value. */
if (neg)
{
bc_divide (one, temp, result, rscale);
bc_free_num (&temp);
}
else
{
bc_free_num (result);
*result = temp;
if ((*result)->n_scale > rscale)
(*result)->n_scale = rscale;
}
bc_free_num (&power);
}

from graphing-calculator-project.

baboomerang avatar baboomerang commented on May 24, 2024

https://www.arduino.cc/en/Math/H
Further insight: Look into how doubles are handled and update the built in log table for arduino. (If I have to)
double atan (double __x) // arc tangent of x
double atan2 (double __y, double __x) // arc tangent of y/x
double log (double __x) // natural logarithm of x
double log10 (double __x) // logarithm of x to base 10.
double pow (double __x, double __y) // x to power of y
double square (double __x) // square of x

from graphing-calculator-project.

baboomerang avatar baboomerang commented on May 24, 2024

http://stackoverflow.com/questions/34239178/how-does-an-avr-perform-floating-point-arithmetic
It would be good to learn from the resources in this thread.

from graphing-calculator-project.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.