Re: Print value of p from the infinite series



Leah wrote:
Now, I only thinking that is this the correct way to do it or not
accurate at all? Is it a sane way to change the expression to:

for (int i = 1; p != 3.141; i += 2)

some sort of that, but how to tell compiler only compare decimal
points as needed?

It depends on what you need, but for this type of algorithm the usual approach is to compare the difference between p and the target value to a small value epsilon, like this:

while ( (p - Math.PI) < 1E-6 )
or
for ( int i = 1; (p - Math.PI) < 1E-6; i += 2 )

Use your own values for the target and epsilon.

- Lew
.



Relevant Pages

  • Re: Build your own Forth for Microchip PIC (Episode 837)
    ... the unreasonablly small hardware stack size for my particular target. ... You are handcuffed in the sense that you would like to be able to download small amounts of code into ram and execute it. ... because once you do away with the inner interpreter, ... An optimizing compiler isn't a post-processor, it's an *alternative* to another kind of compiler. ...
    (comp.lang.forth)
  • Re: Build your own Forth for Microchip PIC (Episode 837)
    ... put those tokens in RAM. ... This is the reason I'm wanting to use the host as a remote execution ... Test/Debug code on target recompiling and reloading as necessary. ... of implementing anything other than a batch forth compiler for it. ...
    (comp.lang.forth)
  • Re: Build your own Forth for Microchip PIC: Design thoughts
    ... compiler is the only task that's burning in my brain right. ... that puts PIC code on the host for the simulator to execute. ... I'm not so sure about the simulator. ... That target will execute compiled forth words. ...
    (comp.lang.forth)
  • Re: forthday proceedings
    ... for target chips in colorforth and reviewed a version ... and with a target compiler and software simulator ... other OKAD application programs and the chip designs ...
    (comp.lang.forth)
  • Re: Build your own Forth for Microchip PIC: Design thoughts
    ... testing words on the host, then transferring words to the target. ... where the students would be ultimately working with a cross-compiler, ... to a different compiler that will generate PIC code and download it. ...
    (comp.lang.forth)