a few thoughts for ruby...

R

Roger Pack

Could you possibly start a different thread for each topic? Bunching
them together makes it very labor-intensive to try to follow the thread
if one is interested in a specific point, and impossible to tell who has
responded to what without going through six topics' worth of posts.

Great idea.
-=r
 
R

Roger Pack

Doing a quick bit of testing suggested that using "%f" % float
might be better than using float.to_s because in some cases
the former preserves information that is actually in the float
which the latter uses. In fact, I was going to suggest you propose
to use "%f" % self in Float#to_d instead of self.to_s.
But after some more thought and a bit of testing, I found that
for me in IRB "%f" % float only gives results to 6 decimal places
but float.to_s seems to give results to 14 or 15 significant figures
so overall using float.to_s for the conversion seems better.

The good news is that with current ruby trunk I believe that Float#to_s
is as accurate as doing a ("%f" % self) [it no longer loses accuracy].

If we want a BigDecimal method (and in view of BigDecimal( float.to_s )
I don't think we do - but BigDecimal( float.to_s ) should perhaps
be mentioned prominently in BigDecimal documentation)
how about something like (not tested):
def BigDecimal.from_f( f )
if f.kind_of?( Float ) then BigDecimal( f.to_s )
else raise "BigDecimal.from_f: argument must be a Float"
end
end

That would be nice, though the way you suggested earlier (require
'bigdecimal/util'; 3.3.to_d) works for me :)
-=
 
F

Fleck Jean-Julien

Hello,
Yes, quite extensively when generating C code. Would hate to have to use
\{...} instead of {...} for C blocks.

So do I when generating LaTeX code.

Cheers,

--=20
JJ Fleck
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top