Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Is there a better way to call fe(get|set)round?

by Moron (Curate)
on Jul 02, 2007 at 12:52 UTC ( #624430=note: print w/replies, xml ) Need Help??

in reply to Is there a better way to call fe(get|set)round?

Something like ...
package Somename; use Math::BigFloat; sub new { my $class = shift; my $self = bless {}; $self -> { underlying } = Math::BigFloat -> new( @_ ); return ( $self, $class ); } sub fsetround { # e.g. $obj -> fsetround( mode => 'FE_DOWNWARD' ); my $self = shift; my %opt = @_; while ( my ( $k, $v ) = each %opt ) { $self -> { $k } = $v; } # set defaults here e.g. for round by default # to 17 digits from the left $self -> { scale } ||= 17; } sub fgetround my $self = shift; if ( $self -> { mode } eq 'FE_DOWNWARD' ) { my $bf = $self -> { underlying }; return $bf -> ffround( -( $self -> { scale } ) ); } # elsif ... # etc. for the other features of fenv }

^M Free your mind!

Replies are listed 'Best First'.
Re^2: Is there a better way to call fe(get|set)round?
by BrowserUk (Pope) on Jul 02, 2007 at 13:26 UTC

    You missed the point again. The rounding mode being queried or altered by the OP, is that of the math coprocessor and is applied to the results of all FP operations done by it. The 4 modes are as defined by the IEEE Floating Point standard. The two calls, fe(get|set)round are C/C++ compiler provided functions to get/set that hardware rounding mode.

    Moving to using software emulated, infinite precision FP to achieve the same end would for most applications be a disaster. With Math::BigFloat, FP calculations run anything from a few hundred to a few 10s of thousands times more slowly depending upon the configuration and underlying libraries used. Okay if your calculating the final cost of a few dozen items in an IO bound shopiing cart application, but for any kind of serious math, way too slow.

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Yes, exactly. Thanks!

      Owl looked at him, and wondered whether to push him off the tree; but, feeling that he could always do it afterwards, he tried once more to find out what they were talking about.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://624430]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2018-03-18 12:19 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (230 votes). Check out past polls.