[vtkusers] doubles, floats, java

Karin Faulhaber faulhaber at ipf.uni-karlsruhe.de
Fri Jun 29 04:38:53 EDT 2001


Just putting the solution in the archive: 


Hi Jeff,

It looks like this is the solution. Always the same: just WHY didn't I
think of that one :-)

Thanks a lot!!!
Karin


Jeff Lee wrote:
> 
> Karin,
> SetComponent is from vtkDataArray which returns a float.  That is why
> you lose precision.  Try using vtkDoubleArray's interface to set/get
> values.  i.e.
> 
>         double doubleValue = 1234567.12345;
>         doubleArray.InsertValue(0, doubleValue);
>         System.out.println("test1: "+doubleValue);
>         System.out.println("test1: "+doubleArray.GetValue(0));
>         System.out.println("test:
> "+(doubleArray.GetValue(0)-1234567.));
> 
> -Jeff
> 
> Karin Faulhaber wrote:
> 
> > Hi Jeff,
> >
> > > Are you saying that doubles don't provide enough accuracy for your
> >
> > > application?  As long as you are sending doubles across the wire
> > > (through JNI), you'll never lose precision.  It's just when you
> > write
> > > out the numbers to a file that you would likely format the data.
> > > Noone wants to see a 16 digit number on the screen or in a file
> > > unformatted.
> >
> > Doubles with 16 digits should be accurate enough, but look at that:
> >
> >         double doubleValue = 1234567.12345;
> >         doubleArray.SetComponent(0, 0, doubleValue);
> >         System.out.println("test1: "+doubleValue);
> >         System.out.println("test1: "+doubleArray.GetComponent(0,0));
> >
> >         System.out.println("test:
> > "+(doubleArray.GetComponent(0,0)-1234567.));
> >
> > -> The digits at the end are lost:
> >
> > test1: 1234567.12345
> > test1: 1234567.125
> > test: 0.125
> >
> > I'm dealing with very small changes in position of points which
> > _may_ be
> > distributed within an area of some hundreds of kilometers. So even
> > if I
> > don't have to visualize as accurate as that (0.12345) I _do_ need
> > the
> > whole number for the user because he will ask for it.
> > I can subtract the coordinates of the centroid, but still: I either
> > have
> > 7 digits before and 3 or 4 after the decimal point or maybe less
> > before
> > but 5 after it.
> >
> > Anyway, I think I might have to settle for separating the number and
> >
> > keep 1234567 in vtkPoints and the .12345 as 12345 in the associated
> > fieldData ...  We'll see if it works.
> >
> > Thanks for your efforts!
> > Karin
> 
> --
> J.A. Lee
> Software Engineer
> Computational Dynamics North America
> 3 Schoolhouse Lane
> Etna NH, 03750
> ph: 603-643-9993 x109, fax: 603-643-9994
> 
>




More information about the vtkusers mailing list