Skip Menu |

This queue is for tickets about the Imager CPAN distribution.

Report information
The Basics
Id: 97086
Status: resolved
Priority: 0/
Queue: Imager

People
Owner: Nobody in particular
Requestors: Ralf.Neubauer [...] wido.bv.aok.de
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: possible cut&paste error in Mandelbrot/mandel.c
Date: Wed, 9 Jul 2014 14:18:16 +0000
To: "bug-Imager [...] rt.cpan.org" <bug-Imager [...] rt.cpan.org>
From: "Neubauer, Ralf" <ralf.neubauer [...] wido.bv.aok.de>
Hi, Mandelbrot/mandel.c contains the lines: i_color icl[256]; srand(12235); for(i=1;i<256; i++) { icl[i].rgb.r = 100+(int) (155.0*rand()/(RAND_MAX+1.0)); icl[i].rgb.g = 100+(int) (155.0*rand()/(RAND_MAX+1.0)); icl[i].rgb.g = 100+(int) (155.0*rand()/(RAND_MAX+1.0)); } icl[0].rgb.r = 0; icl[0].rgb.g = 0; icl[0].rgb.g = 0; The double assignment to rgb.g does not make sense. I assume that should be: i_color icl[256]; srand(12235); for(i=1;i<256; i++) { icl[i].rgb.r = 100+(int) (155.0*rand()/(RAND_MAX+1.0)); icl[i].rgb.g = 100+(int) (155.0*rand()/(RAND_MAX+1.0)); icl[i].rgb.b = 100+(int) (155.0*rand()/(RAND_MAX+1.0)); } icl[0].rgb.r = 0; icl[0].rgb.g = 0; icl[0].rgb.b = 0; Also to get results in the interval [100, 255] instead of [100, 254] you could assign 100+(int) (156.0*rand()/(RAND_MAX+1.0)) The (int) cast truncates and 155.0 is never reached, because rand()/(RAND_MAX+1.0) < 1. Ralf
On Wed Jul 09 10:19:05 2014, Ralf.Neubauer@wido.bv.aok.de wrote: Show quoted text
> Hi, > > Mandelbrot/mandel.c contains the lines: > > i_color icl[256]; > srand(12235); > for(i=1;i<256; i++) { > icl[i].rgb.r = 100+(int) (155.0*rand()/(RAND_MAX+1.0)); > icl[i].rgb.g = 100+(int) (155.0*rand()/(RAND_MAX+1.0)); > icl[i].rgb.g = 100+(int) (155.0*rand()/(RAND_MAX+1.0)); > } > > icl[0].rgb.r = 0; > icl[0].rgb.g = 0; > icl[0].rgb.g = 0; > > The double assignment to rgb.g does not make sense. I assume that > should be: > > i_color icl[256]; > srand(12235); > for(i=1;i<256; i++) { > icl[i].rgb.r = 100+(int) (155.0*rand()/(RAND_MAX+1.0)); > icl[i].rgb.g = 100+(int) (155.0*rand()/(RAND_MAX+1.0)); > icl[i].rgb.b = 100+(int) (155.0*rand()/(RAND_MAX+1.0)); > } > > icl[0].rgb.r = 0; > icl[0].rgb.g = 0; > icl[0].rgb.b = 0; > > Also to get results in the interval [100, 255] instead of [100, 254] > you could assign > > 100+(int) (156.0*rand()/(RAND_MAX+1.0)) > > The (int) cast truncates and 155.0 is never reached, because > rand()/(RAND_MAX+1.0) < 1.
Thanks, fixed in Imager 1.000. This was also in dynfilt/mandel.c, which I've also fixed. Tony