Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pi generating routine doesn't seem to converge. #1983

Closed
floitschG opened this issue Mar 5, 2012 · 5 comments
Closed

Pi generating routine doesn't seem to converge. #1983

floitschG opened this issue Mar 5, 2012 · 5 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. closed-duplicate Closed in favor of an existing report

Comments

@floitschG
Copy link
Contributor

From the mailing-list:

Thanks for amazing work on dart, I'd like to report a issue on core
library math.

What steps will reproduce the problem ?

  1. run below code by dartVM.

double pi() {
   final double COUNT = Math.pow(10,7);
   final double r = 1.0;
   int hit =0;

   for(int i=0; i<COUNT; i++) {
       double x = Math.random();
       double y = Math.random();

       if( Math.sqrt(Math.pow(x,2) + Math.pow(y,2)) <= r ) {
           hit ++;
       }
   }

   return ( 4.00000 * hit / COUNT) ;
}

main() {
   Stopwath watch = new Stopwatch();

   watch.start();
   print( pi() );
   watch.stop();

   print("time used: ${watch.elapsedInMs() }");
}
2. The performance also need to improved, about 10x slow than run on
V8.

What is the expected output? What do you see instead?

expected value is round 3.14 but get 2.9310668 in fact. If I compile
it to javascript by frogc, get 3.142088.

What version of the product are you using? On what operating system?
dartvm 4800

Please provide any additional information below.

http://www.juanhu.name/dartvm-performance.html

@floitschG
Copy link
Contributor Author

My guess is that this is a duplicate of issue #499.

@DartBot
Copy link

DartBot commented Mar 5, 2012

This comment was originally written by danri...@gmail.com


The following program produces a plot of (x, y) pairs from Math.random. If you view the output in a postscript interpreter, you will not be surprised that the answer doesn't converge to PI. :-)

class Random {

  Random() {
  }

  void run() {
    print('''
%!PS

matrix currentmatrix /originmat exch def
/umatrix {originmat matrix concatmatrix setmatrix} def
[28.3465 0 0 28.3465 10.5 100.0] umatrix
20 20 scale
    
0 setgray
0 setlinewidth

0 0 newpath moveto
1 0 lineto
1 1 lineto
0 1 lineto
closepath
stroke

0.001 setlinewidth 1 setlinecap

/pt { 1 index 1 index moveto lineto stroke} def
''');
    for (int i = 0; i < 10000; i++) {
      double x = Math.random();
      double y = Math.random();
      print("$x $y pt");
    }
    print("showpage");
  }
}

@whesse
Copy link
Contributor

whesse commented Mar 5, 2012

The prng generates one random bit at a time, so if you generate about 30 random numbers after x, and after y, then you should get a reasonable answer.


Added Duplicate label.
Marked as being merged into #499.

@DartBot
Copy link

DartBot commented Mar 5, 2012

This comment was originally written by danri...@gmail.com


I've attached a screen shot of (x, y) pairs where 32 random numbers are discarded between selecting x and y. It's better, but still not really usable.


Attachment:
[Screen shot 2012-03-05 at 12.24.34 PM.png](https://storage.googleapis.com/google-code-attachments/dart/issue-1983/comment-4/Screen shot 2012-03-05 at 12.24.34 PM.png) (156.47 KB)

@DartBot
Copy link

DartBot commented Mar 5, 2012

This comment was originally written by danr...@gmail.com


Here is the screnshot for comment #­2.


Attachment:
[Screen shot 2012-03-05 at 1.37.30 PM.png](https://storage.googleapis.com/google-code-attachments/dart/issue-1983/comment-5/Screen shot 2012-03-05 at 1.37.30 PM.png) (34.06 KB)

@floitschG floitschG added Type-Defect area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. closed-duplicate Closed in favor of an existing report labels Mar 5, 2012
copybara-service bot pushed a commit that referenced this issue Feb 23, 2023
Revisions updated by `dart tools/rev_sdk_deps.dart`.

dartdoc (https://github.com/dart-lang/dartdoc/compare/dba6f94..e4cdbd6):
  e4cdbd6f  2023-02-21  Janice Collins  Record rendering simplification (#3344)

http (https://github.com/dart-lang/http/compare/c13a3f8..1500a71):
  1500a71  2023-02-23  Devon Carew  contribute a pull request labeler workflow (#875)
  e2c4e6f  2023-02-21  Brian Quinlan  Add a link to cronet_http_embedded from cronet_http. (#874)

markdown (https://github.com/dart-lang/markdown/compare/4befe66..ecbffa9):
  ecbffa9  2023-02-22  Kevin Moore  Use latest lints, require Dart 2.19 or later (#524)

shelf (https://github.com/dart-lang/shelf/compare/707c8b2..e3cfe79):
  e3cfe79  2023-02-22  Devon Carew  contribute issue templates and a pull request labeler (#332)

test (https://github.com/dart-lang/test/compare/e56c643..2cc4144):
  2cc4144e  2023-02-22  Nate Bosch  Avoid exceptions for iterable getters (#1954)
  f7fe4f06  2023-02-22  Nate Bosch  Include stack trace for exception in has (#1953)
  ba8e43af  2023-02-22  Nate Bosch  Only grab the first failure in softCheck (#1949)
  34df652b  2023-02-22  Nate Bosch  Flush stdin before test (#1950)
  ae015ef6  2023-02-22  Nidal Bakir  Add Concurrency Testing section to README (#1944)
  4e23d036  2023-02-21  Nate Bosch  Mention .having and .has in migration guide (#1948)
  438c2274  2023-02-21  Nate Bosch  Annotate `has` with `@useResult` (#1947)
  3ddecafd  2023-02-21  Nate Bosch  Add async examples to README (#1946)

tools (https://github.com/dart-lang/tools/compare/a53933c..c7518f7):
  c7518f7  2023-02-22  Elias Yishak  Update to regex to look for underscore delimited labels (#12)

webdev (https://github.com/dart-lang/webdev/compare/ae7eb80..1e7f9b7):
  1e7f9b7  2023-02-22  Anna Gringauze  Create copying sdk configuration provider (#1984)
  26910ba  2023-02-22  Anna Gringauze  Pass SdkLayout to the frontend server (#1986)
  784e28b  2023-02-22  Anna Gringauze  Remove unnecessary awaits (#1982)
  3cbaf37  2023-02-22  Elliott Brooks (she/her)  [MV3 Debug Extension] Support Bolt workflow (#1983)
  0f893e6  2023-02-22  Anna Gringauze  Move project definitions into a separate class (#1975)
  a942b5f  2023-02-22  Anna Gringauze  Add unnecessary_lambdas lint (#1978)
  3774cf8  2023-02-21  Anna Gringauze  Add 'avoid_void_async' lint (#1977)
  705e0ac  2023-02-21  Elliott Brooks (she/her)  [MV3 Debug Extension] Show a warning if multiple Dart apps are in a single page (#1976)

Change-Id: Iea264a18a154e71cd0990e1363951648bec5ceba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284940
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Auto-Submit: Devon Carew <devoncarew@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. closed-duplicate Closed in favor of an existing report
Projects
None yet
Development

No branches or pull requests

3 participants