From: <ai...@us...> - 2008-08-07 22:04:12
|
Revision: 8613 http://plplot.svn.sourceforge.net/plplot/?rev=8613&view=rev Author: airwin Date: 2008-08-07 22:04:18 +0000 (Thu, 07 Aug 2008) Log Message: ----------- Change colour multiplier from 255 to 255.001 to avoid close truncation decisions that will vary with different floating point implementations. Modified Paths: -------------- trunk/examples/ada/x02a.adb.cmake trunk/examples/ada/xthick02a.adb.cmake trunk/examples/c/x02c.c trunk/examples/c++/x02.cc trunk/examples/f77/x02f.fm4 trunk/examples/f95/x02f.f90 trunk/examples/java/x02.java trunk/examples/ocaml/x02.ml trunk/examples/perl/x02.pl trunk/examples/python/xw02.py trunk/examples/tcl/x02.tcl Modified: trunk/examples/ada/x02a.adb.cmake =================================================================== --- trunk/examples/ada/x02a.adb.cmake 2008-08-07 21:10:21 UTC (rev 8612) +++ trunk/examples/ada/x02a.adb.cmake 2008-08-07 22:04:18 UTC (rev 8613) @@ -138,9 +138,9 @@ -- number to use appears to be about 0.5 - 10^-16 which _might_ -- be an exact fix for 64-bit floats since they have about 16 digits -- of accuracy. - r(i+16) := Integer((r1 * 255.0) - 0.499999999999999); - g(i+16) := Integer((g1 * 255.0) - 0.499999999999999); - b(i+16) := Integer((b1 * 255.0) - 0.499999999999999); + r(i+16) := Integer((r1 * 255.001) - 0.499999999999999); + g(i+16) := Integer((g1 * 255.001) - 0.499999999999999); + b(i+16) := Integer((b1 * 255.001) - 0.499999999999999); end loop; -- Load default cmap0 colors into our custom set. Modified: trunk/examples/ada/xthick02a.adb.cmake =================================================================== --- trunk/examples/ada/xthick02a.adb.cmake 2008-08-07 21:10:21 UTC (rev 8612) +++ trunk/examples/ada/xthick02a.adb.cmake 2008-08-07 22:04:18 UTC (rev 8613) @@ -136,9 +136,9 @@ -- approximately like C to match that example. -0.5 produces -- at least one -1 result (rather than zero) so we subtract -- something with a slightly smaller absolute value. - r(i+16) := Integer((r1 * 255.0) - 0.499999999999999); - g(i+16) := Integer((g1 * 255.0) - 0.499999999999999); - b(i+16) := Integer((b1 * 255.0) - 0.499999999999999); + r(i+16) := Integer((r1 * 255.001) - 0.499999999999999); + g(i+16) := Integer((g1 * 255.001) - 0.499999999999999); + b(i+16) := Integer((b1 * 255.001) - 0.499999999999999); end loop; -- Load default cmap0 colors into our custom set. Modified: trunk/examples/c/x02c.c =================================================================== --- trunk/examples/c/x02c.c 2008-08-07 21:10:21 UTC (rev 8612) +++ trunk/examples/c/x02c.c 2008-08-07 22:04:18 UTC (rev 8613) @@ -93,16 +93,21 @@ s = 1.0; plhlsrgb(h, l, s, &r1, &g1, &b1); + /*printf("%3d %15.9f %15.9f %15.9f %15.9f %15.9f %15.9f\n", + i+16,h,l,s,r1,g1,b1); */ - r[i+16] = r1 * 255; - g[i+16] = g1 * 255; - b[i+16] = b1 * 255; + /* Use 255.001 to avoid close truncation decisions in this example. */ + r[i+16] = r1 * 255.001; + g[i+16] = g1 * 255.001; + b[i+16] = b1 * 255.001; } /* Load default cmap0 colors into our custom set */ for (i = 0; i <= 15; i++) plgcol0(i, &r[i], &g[i], &b[i]); +/* for (i = 0; i < 116; i++) + printf("%3d %3d %3d %3d \n", i, r[i], g[i], b[i]); */ /* Now set cmap0 all at once (faster, since fewer driver calls) */ plscmap0(r, g, b, 116); Modified: trunk/examples/c++/x02.cc =================================================================== --- trunk/examples/c++/x02.cc 2008-08-07 21:10:21 UTC (rev 8612) +++ trunk/examples/c++/x02.cc 2008-08-07 22:04:18 UTC (rev 8613) @@ -109,9 +109,9 @@ pls->hlsrgb(h, l, s, &r1, &g1, &b1); - r[i+16] = (PLINT)(r1 * 255); - g[i+16] = (PLINT)(g1 * 255); - b[i+16] = (PLINT)(b1 * 255); + r[i+16] = (PLINT)(r1 * 255.001); + g[i+16] = (PLINT)(g1 * 255.001); + b[i+16] = (PLINT)(b1 * 255.001); } // Load default cmap0 colors into our custom set Modified: trunk/examples/f77/x02f.fm4 =================================================================== --- trunk/examples/f77/x02f.fm4 2008-08-07 21:10:21 UTC (rev 8612) +++ trunk/examples/f77/x02f.fm4 2008-08-07 22:04:18 UTC (rev 8613) @@ -95,9 +95,9 @@ call plhlsrgb(h, l, s, r1, g1, b1) - r(i+17) = r1*255 - g(i+17) = g1*255 - b(i+17) = b1*255 + r(i+17) = r1*255.001 + g(i+17) = g1*255.001 + b(i+17) = b1*255.001 enddo do i=1,16 Modified: trunk/examples/f95/x02f.f90 =================================================================== --- trunk/examples/f95/x02f.f90 2008-08-07 21:10:21 UTC (rev 8612) +++ trunk/examples/f95/x02f.f90 2008-08-07 22:04:18 UTC (rev 8613) @@ -96,9 +96,9 @@ call plhlsrgb(h, l, s, r1, g1, b1) - r(i+17) = r1*255 - g(i+17) = g1*255 - b(i+17) = b1*255 + r(i+17) = r1*255.001 + g(i+17) = g1*255.001 + b(i+17) = b1*255.001 enddo do i=1,16 Modified: trunk/examples/java/x02.java =================================================================== --- trunk/examples/java/x02.java 2008-08-07 21:10:21 UTC (rev 8612) +++ trunk/examples/java/x02.java 2008-08-07 22:04:18 UTC (rev 8613) @@ -117,9 +117,9 @@ pls.hlsrgb(h, l, s, r1, g1, b1); - r[i+16] = (int)(r1[0] * 255); - g[i+16] = (int)(g1[0] * 255); - b[i+16] = (int)(b1[0] * 255); + r[i+16] = (int)(r1[0] * 255.001); + g[i+16] = (int)(g1[0] * 255.001); + b[i+16] = (int)(b1[0] * 255.001); } // Load default cmap0 colors into our custom set Modified: trunk/examples/ocaml/x02.ml =================================================================== --- trunk/examples/ocaml/x02.ml 2008-08-07 21:10:21 UTC (rev 8612) +++ trunk/examples/ocaml/x02.ml 2008-08-07 22:04:18 UTC (rev 8613) @@ -101,9 +101,9 @@ let (r1, g1, b1) = plhlsrgb h l s in - r.(i+16) <- int_of_float (r1 *. 255.); - g.(i+16) <- int_of_float (g1 *. 255.); - b.(i+16) <- int_of_float (b1 *. 255.); + r.(i+16) <- int_of_float (r1 *. 255.001); + g.(i+16) <- int_of_float (g1 *. 255.001); + b.(i+16) <- int_of_float (b1 *. 255.001); done; (* Load default cmap0 colors into our custom set *) Modified: trunk/examples/perl/x02.pl =================================================================== --- trunk/examples/perl/x02.pl 2008-08-07 21:10:21 UTC (rev 8612) +++ trunk/examples/perl/x02.pl 2008-08-07 22:04:18 UTC (rev 8613) @@ -109,9 +109,9 @@ ($r1, $g1, $b1) = plhlsrgb($h, $l, $s); - set $r, i+16, r1 * 255; - set $g, i+16, g1 * 255; - set $b, i+16, b1 * 255; + set $r, i+16, r1 * 255.001; + set $g, i+16, g1 * 255.001; + set $b, i+16, b1 * 255.001; } # Load default cmap0 colors into our custom set Modified: trunk/examples/python/xw02.py =================================================================== --- trunk/examples/python/xw02.py 2008-08-07 21:10:21 UTC (rev 8612) +++ trunk/examples/python/xw02.py 2008-08-07 22:04:18 UTC (rev 8613) @@ -54,9 +54,9 @@ rgb = plhlsrgb(h, l, s) - r[i+16] = rgb[0]*255 - g[i+16] = rgb[1]*255 - b[i+16] = rgb[2]*255 + r[i+16] = rgb[0]*255.001 + g[i+16] = rgb[1]*255.001 + b[i+16] = rgb[2]*255.001 # Load default cmap0 colors into out custom set for i in range(16): Modified: trunk/examples/tcl/x02.tcl =================================================================== --- trunk/examples/tcl/x02.tcl 2008-08-07 21:10:21 UTC (rev 8612) +++ trunk/examples/tcl/x02.tcl 2008-08-07 22:04:18 UTC (rev 8613) @@ -72,20 +72,37 @@ set s 1.0 plhlsrgb $h $l $s r1 g1 b1 + # puts [format "%3d %15.9f %15.9f %15.9f %15.9f %15.9f %15.9f" $i1 $h $l $s $r1 $g1 $b1] if $see_the_bug { - r $i1 = [expr int($r1 * 255)] - g $i1 = [expr int($g1 * 255)] - b $i1 = [expr int($b1 * 255)] + r $i1 = [expr int($r1 * 255.001)] + g $i1 = [expr int($g1 * 255.001)] + b $i1 = [expr int($b1 * 255.001)] } else { - set r2 [expr int($r1 * 255)] - set g2 [expr int($g1 * 255)] - set b2 [expr int($b1 * 255)] + set r2 [expr int($r1 * 255.001)] + set g2 [expr int($g1 * 255.001)] + set b2 [expr int($b1 * 255.001)] + # puts [format "%3d %3d %3d %3d" $i1 $r2 $g2 $b2] plscol0 $i1 $r2 $g2 $b2 } } if $see_the_bug { - plscmap0 r g b $ntot + # Load default cmap0 colors into our custom set + for {set i 0} {$i < $offset} {incr i} { + plgcol0 $i r1 g1 b1 + r $i = [expr int($r1)] + g $i = [expr int($g1)] + b $i = [expr int($b1)] + } + # temporary + for {set i 0} {$i < $ntot} {incr i} { + set r1 [expr [r $i]] + set g1 [expr [g $i]] + set b1 [expr [b $i]] + puts [format "%3d %3d %3d %3d" $i $r1 $g1 $b1] + } + # The following call currently segfaults. + plscmap0 r g b $ntot } x02_draw_windows $w 100 $offset This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |