|
![](/i/fill.gif) |
In article <405dfd16$1@news.povray.org>, Darren New <dne### [at] san rr com>
wrote:
> Christopher James Huff wrote:
> > Hmm...yes it is. To write "1.5" in a portable way in text only requires
> > writing those three characters.
>
> Along with a flag that says it's three characters.
No. You just have to say "write this float". The C and C++ standard
libraries already have the capability of doing this. "strm << floatVal;"
is a lot easier than writing your own function or tracking down some
library to do it.
> And how do you think you get a floating-point 1.5 into those three
> characters? :-)
By calling the appropriate standard function.
> The fact that it's built into the language doesn't make
> it easier. It just makes it built in.
It does make it easier. If it's already there, you don't have to write
it.
> I disagree. See above. Text formatting of integers is built into the
> language. Try to output that 1.5 using nothing but putc() and knowing
> nothing about the internal representation of floats, and you'll find
> it's not as simple as you think. You tend to get things like
> 1.499999999978 and you have to know the actual binary size of your
> floating point numbers anyway in order to stop at the right place.
Of course it's harder if you do it the hard way. My point is that
there's an existing easy way, which doesn't exist for binary data. And
you lose information in the base conversion...but there's no guarantee
the native format on a foreign machine will be the same anyway. You get
something that works for almost everything with very little effort, and
most people stop there.
> Well, actually, there is. ntoh() and hton(), Sun's XDR libraries, any
> ASN.1 library, etc etc. Plus, move to any language that's actually been
> invented in the last 20 years or so, and it probably has libraries for
> doing this.
ntoh() and hton() don't appear to be standard. Sun's XDR libraries are
Sun's, you gotta go get them. I know it's a pretty much solved problem,
and was never very difficult, but it is still one more hurdle to go
over. And many projects (like POV) use C or C++, moving to a language
that has standard support is not always practical. This is one of my
peeves about C/C++...any language I design that has file I/O will be
able to read and write floats and integers in a platform independent way.
--
Christopher James Huff <cja### [at] earthlink net>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tag povray org>
http://tag.povray.org/
Post a reply to this message
|
![](/i/fill.gif) |