Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Detecting whether UV fits into an NV

by GrandFather (Sage)
on Feb 26, 2020 at 03:29 UTC ( #11113422=note: print w/replies, xml ) Need Help??


in reply to Detecting whether UV fits into an NV

Is this an "It annoys me because"

  1. it doesn't look elegant
  2. my application needs it to be performant and even a short loop isn't
  3. some other reason I'm going to tell you about

If it is case 1 then I suspect you are out of luck. The only other ways I can think of doing it are even worse, or hardware dependent, or are a maintenance nightmare.

For case 2 there are techniques like binary searches that maybe can run faster or a really nasty looking series of if statements that amount to unrolling the while loop.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
  • Comment on Re: Detecting whether UV fits into an NV

Replies are listed 'Best First'.
Re^2: Detecting whether UV fits into an NV
by syphilis (Bishop) on Feb 26, 2020 at 05:58 UTC
    I'm just looking at the lack of elegance - that's pretty much it.
    I've no objection to inelegant code (of which I've written heaps) if it needs to be that way.
    If not for the portability concerns, I'd pick up on stevieb's suggestion and just have the XSub as :
    int uv_fits_double(UV arg) { arg >>= __builtin_ctzll(arg); if(arg < 9007199254740993) return 1; return 0; }
    That seems to work fine on MinGW-built Windows perls, where $Config{ivtype} is 'long long', and I'd be happy with that even if it wasn't any more efficient.
    I didn't know about the existence of __builtin_ctz() and friends. Thanks, stevieb for bringing it to my attention. I'll do some benchmarking later on, and see how much time it saves.
    It's an option that could come in handy to me in the future.

    I guess that, mainly, I just want to know if there are some more elegant (&& portable) options available.

    Cheers,
    Rob

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2020-10-01 17:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (17 votes). Check out past polls.

    Notices?