Subject:
|
Re: Some comments on LPub
|
Newsgroups:
|
lugnet.cad
|
Date:
|
Tue, 22 Mar 2005 17:54:02 GMT
|
Viewed:
|
941 times
|
| |
| |
Kevin L. Clague wrote:
> > a) For instance, when "l3p_use_seam_width true 0.800000" is in
> > the config file, then after loading, the seam value appears in LPub
> > as 0.800000011920929.
> > [...]
> > "color_scaling 0.650000 ..." in the config file, it is shown as
> > 36/64% in L3Pub after loading that config, and after saving it, it
> > is "color_scaling 0.640000 ..." in the config file. Subsequent
> > "0.996094 0.996094 0.996094".
>
> I will study this problem. I'm sure that I am just using
> sprintf("%f"), and sscanf("%f"), so I'm not sure what to do here.
> Anyone out there got ideas on this?
This is exactly what happens when you read string numbers into a float (or
Pascal single) and then convert it to a double (or extended). Floating point
numbers are never exact in computers, and storing them with limited
precision (sprintf("%f")) will not make the situation better.
I don't remember C formatting exactly, but in Pascal I would use the '%g'
format (15 digits of precision) on writing, maybe with an additional
precision specifier, '%9g', to limit the size of the output.
The last one, 0.996094 would be better expressed as 0.99609375, see in the
details below.
Hope this helps.
(If you care about the gory details, you can read the following)
--- WARNING - Geeky material below ---
Output from John Herbsters ExactFloatToStr,
http://codecentral.borland.com/codecentral/ccweb.exe/author?authorid=358
with a slight addition from me to get all three sizes.
John has also published a very comprehensive rounding package where you can
get exactly the kind of rounding you want (whatever you want!)
http://codecentral.borland.com/codecentral/ccweb.exe/listing?id=21909
Here you can see that the 'sprintf'-generated output ('G=...') differs when
using different sizes of floats. Also note that depending on the precision,
the actual value may be larger or smaller than the intended value. Coupled
with rounding or truncation this can lead to the symptoms described above.
Calling: Exp=$3FFE, Man=$CCCCCCCCCCCCCCCD, G=0.8
Required + 224 265 clock cycles
+ 0.800 000 000 000 000 000 010 842 021 724 855 044 340 074 528 008 699 417
114 257 812 5
Calling: Exp=$3FFE, Man=$CCCCCCCCCCCCD000, G=0.8
Required + 148 974 clock cycles
+ 0.800 000 000 000 000 044 408 920 985 006 261 616 945 266 723 632 812 5
Calling: Exp=$3FFE, Man=$CCCCCD0000000000, G=0.800000011920929
Required + 58 657 clock cycles
+ 0.800 000 011 920 928 955 078 125
Calling: Exp=$3FFE, Man=$A666666666666666, G=0.65
Required + 194 524 clock cycles
+ 0.649 999 999 999 999 999 978 315 956 550 289 911 319 850 943 982 601 165
771 484 375
Calling: Exp=$3FFE, Man=$A666666666666800, G=0.65
Required + 147 348 clock cycles
+ 0.650 000 000 000 000 022 204 460 492 503 130 808 472 633 361 816 406 25
Calling: Exp=$3FFE, Man=$A666660000000000, G=0.649999976158142
Required + 55 900 clock cycles
+ 0.649 999 976 158 142 089 843 75
The last one, 0.996094 would be better expressed as 0.99609375 (255/256), as
Calling: Exp=$3FFE, Man=$FF000431BDE82D7B, G=0.996094
Required + 213 769 clock cycles
+ 0.996 093 999 999 999 999 978 971 682 024 209 144 401 538 651 436 567 306
518 554 687 5
Calling: Exp=$3FFE, Man=$FF000431BDE83000, G=0.996094
Required + 147 425 clock cycles
+ 0.996 094 000 000 000 034 944 491 744 681 727 141 141 891 479 492 187 5
Calling: Exp=$3FFE, Man=$FF00040000000000, G=0.996093988418579
Required + 55 007 clock cycles
+ 0.996 093 988 418 579 101 562 5
and
Calling: Exp=$3FFE, Man=$FF00000000000000, G=0.99609375
Required + 32 982 clock cycles
+ 0.996 093 75
Calling: Exp=$3FFE, Man=$FF00000000000000, G=0.99609375
Required + 24 152 clock cycles
+ 0.996 093 75
Calling: Exp=$3FFE, Man=$FF00000000000000, G=0.99609375
Required + 24 020 clock cycles
+ 0.996 093 75
--
Anders Isaksson, Sweden
BlockCAD: http://web.telia.com/~u16122508/proglego.htm
Gallery: http://web.telia.com/~u16122508/gallery/index.htm
|
|
Message has 1 Reply:
Message is in Reply To:
| | Re: Some comments on LPub
|
| (...) Andy, I'm very impressed with this post on LPub. You are very thorough, and it is clear you've done your homework before asking questions. It is some of the best LPub feedback I've ever gotten. (...) Yes. Hopefully I won't make the same (...) (20 years ago, 22-Mar-05, to lugnet.cad)
|
10 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|