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

Re^12: Algorithm for cancelling common factors between two lists of multiplicands

by BrowserUk (Patriarch)
on Aug 09, 2005 at 02:04 UTC ( #482097=note: print w/replies, xml ) Need Help??


in reply to Re^11: Algorithm for cancelling common factors between two lists of multiplicands
in thread Algorithm for cancelling common factors between two lists of multiplicands

How do I get that output reduced to a real in scientific format?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
  • Comment on Re^12: Algorithm for cancelling common factors between two lists of multiplicands
  • Download Code

Replies are listed 'Best First'.
Re^13: Algorithm for cancelling common factors between two lists of multiplicands
by tmoertel (Chaplain) on Aug 09, 2005 at 06:16 UTC
    How do I get that output reduced to a real in scientific format?
    If you want arbitrary precision, the safest bet is to extract the digits yourself:
    module ScientificFormat (sciformat) where import Ratio -- return prec+1 digits because I don't round sciformat prec r = sign ++ digits ++ "e" ++ show exp where (ds, exp) = tosci (abs numer) (denominator r) 0 numer = numerator r sign = if signum numer < 0 then "-" else "+" digits = show (head ds') ++ "." ++ concatMap show (tail ds') ds' = take (prec+1) (ds ++ repeat 0) tosci 0 _ _ = ([0], 0) tosci numer denom exp = case numer `div` denom of 0 -> tosci (10 * numer) denom (exp-1) x | x >= 10 -> tosci numer (10*denom) (exp+1) _ -> (digits numer denom, exp) digits n d = let (q,r) = n `quotRem` d in q : digits (10*r) d
    And:
    module Main (main) where import FishersExactTest import ScientificFormat main = interact $ sciformat 60 . pCutoff . map (map read . words) . li +nes
    Example:
    [thor@arinmir fishers-exact-test]$ time ./fet < ex1.dat +8.070604647867604097576877675243109941729476950993498765160880e-7030 real 0m0.839s user 0m0.819s sys 0m0.016s

    Cheers,
    Tom

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2023-03-24 09:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (60 votes). Check out past polls.

    Notices?