Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^4: Anyone with XS experience willing to create a high performance data type for Perl?

by jdporter (Paladin)
on Nov 10, 2021 at 17:59 UTC ( [id://11138700]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Anyone with XS experience willing to create a high performance data type for Perl?
in thread Anyone with XS experience willing to create a high performance data type for Perl?

10 and 99 (1E1 and 9.9E1) are the same order of magnitude, but 99 and 100 (9.9E1 and 1E2) are different orders of magnitude

No. That's the problem with taking such a definition literally. The "order of magnitude" of a number is its base-10 logarithm, usually rounded to the nearest whole number.

Try this: round( log10(X) - log10(Y) )

In terms of "order of magnitude", 99 and 100 are the same number.

I reckon we are the only monastery ever to have a dungeon staffed with 16,000 zombies.
  • Comment on Re^4: Anyone with XS experience willing to create a high performance data type for Perl?

Replies are listed 'Best First'.
Re^5: Anyone with XS experience willing to create a high performance data type for Perl?
by talexb (Chancellor) on Nov 11, 2021 at 01:05 UTC

    :) OK, then, I guess I need to move my scale around. I could have said that 31 and 32 are different orders of magnitude (log of 31 is 1.49, log of 32 is 1.51).

    Using this (corrected) scale, 33 and 2 are actually two orders of magnitude apart (log of 33 is 1.51, log of 2 is of course .30). Two orders does count as 'several' orders, but a 16x difference, while large, is not gigantic. A recent improvement at work sped a database operation up from 5-6 minutes to about 15-20 seconds -- about a 20x improvement. I was happy with that.

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

      I could have said that 31 and 32 are different orders of magnitude (log of 31 is 1.49, log of 32 is 1.51)

      That would mean you still weren't getting it. You have to round after doing the difference, not before.

      You could also think of it like this, which is mathematically equivalent: round( log10( X / Y ) ).

      I reckon we are the only monastery ever to have a dungeon staffed with 16,000 zombies.

        OK -- thank you, I get it now. I was looking at absolute orders of magnitude, when I should have been looking at relative orders of magnitude.

        Alex / talexb / Toronto

        Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

      FWIW the WP article only talks about truncating (int) not rounding the logarithm.

      But they also claim that Saturn with factor 95 has 2 magnitudes more mass than earth. 🤷🏻‍♂️

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11138700]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 21:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found