Help with decimal places

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Help with decimal places

Simon Phillip Freidin

Hi All

 

I have data which I thought was truncated to 2 decimal digit precision.

 

 However nothing I try stores it without imprecise repeating 9's (because it is stored as an exponential?; or is it a list and format problem?)

 

Test program below, I would have expected 1.6299999999999990 -> 1.6300000000000000

 

Can someone explain or give a workaround?

 

Does it have anything to do with system-wide fuzzbits?

 

thanks

Simon

 

data list list/x (f33.16).

begin data.

 1.5500000000000000

 1.6299999999999990

-1.0000000000000000

 6.5199999999999900

  .9900000000000000

  .2700000000000000

end data.

compute x=rnd(x*100)/100.

list/x.

compute x=trunc(x*100)/100.

list/x.

 

/* SPSS 18.0.2 & 19.0.0.1 on 64-bit Windows 7; i7 */

Reply | Threaded
Open this post in threaded view
|

Re: Help with decimal places

David Marso
Administrator
Simon,
It would be useful/"*essential*" for you to post the results of the two computations you appear to have attempted ;-)
--
compute x=rnd(x*100)/100.
list/x.
compute x=trunc(x*100)/100.
list/x.
I was going to post the rnd version as a 'workaround' (trunc is *NOT* what you want here) and it should serve to blast any decimals beyond the 2nd.  Difficult/"*impossible*" to believe something this fundamental was botched in implementation and then slipped through QA and beta testing.  OTOH, M$ somehow got Vista shipped ;-)

Simon Phillip Freidin wrote
Hi All

I have data which I thought was truncated to 2 decimal digit precision.

 However nothing I try stores it without imprecise repeating 9's (because it is stored as an exponential?; or is it a list and format problem?)

Test program below, I would have expected 1.6299999999999990 -> 1.6300000000000000

Can someone explain or give a workaround?

Does it have anything to do with system-wide fuzzbits?

thanks
Simon

data list list/x (f33.16).
begin data.
 1.5500000000000000
 1.6299999999999990
-1.0000000000000000
 6.5199999999999900
  .9900000000000000
  .2700000000000000
end data.
compute x=rnd(x*100)/100.
list/x.
compute x=trunc(x*100)/100.
list/x.

/* SPSS 18.0.2 & 19.0.0.1 on 64-bit Windows 7; i7 */
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Help with decimal places

Garry Gelade
In reply to this post by Simon Phillip Freidin

Dear Simon

 

I am also using SPSS 18 under windows 7 64-bit. I attempted to reproduce your problem, and did so, but there’s something else. Here’s what happens to me.

 

DATA LIST list/x (F33.16) .

begin data.

1.5500000000000000

1.6299999999999990

-1.0000000000000000

6.5199999999999900

  .9900000000000000

  .2700000000000000

end data.

 

LIST.

 

1.5500000000000000

1.6299999999999990

-1.0000000000000000

6.5199999999999900

.9900000000000000

.2700000000000000

 

So far so good, but look at what is in the data editor.

 

1.5500000000000000

1.6299999999999990

-1.0000000000000000

6.5199999999999910

.9900000000000000

.2700000000000000

 

Can you see the difference? The fourth entry is different in the 15th place to what was specified in DATA LIST and reported by LIST.

 

Garry

 

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Simon Phillip Freidin
Sent: 29 July 2011 08:05
To: [hidden email]
Subject: Help with decimal places

 

Hi All

 

I have data which I thought was truncated to 2 decimal digit precision.

 

 However nothing I try stores it without imprecise repeating 9's (because it is stored as an exponential?; or is it a list and format problem?)

 

Test program below, I would have expected 1.6299999999999990 -> 1.6300000000000000

 

Can someone explain or give a workaround?

 

Does it have anything to do with system-wide fuzzbits?

 

thanks

Simon

 

data list list/x (f33.16).

begin data.

 1.5500000000000000

 1.6299999999999990

-1.0000000000000000

 6.5199999999999900

  .9900000000000000

  .2700000000000000

end data.

compute x=rnd(x*100)/100.

list/x.

compute x=trunc(x*100)/100.

list/x.

 

/* SPSS 18.0.2 & 19.0.0.1 on 64-bit Windows 7; i7 */

Reply | Threaded
Open this post in threaded view
|

Re: Help with decimal places

Art Kendall
with this modified syntax I get the output below
data list list/x (f33.16).
begin data.
 1.5500000000000000
 1.6299999999999990
-1.0000000000000000
 6.5199999999999900
  .9900000000000000
  .2700000000000000
end data.
compute x2=rnd(x*100)/100.
compute x3=trunc(x2*100)/100.
formats x to x3 (f21.16).
list.



(fixed pitch font shows better)

                    x                    x2                    x3

   1.5500000000000000    1.5500000000000000    1.5500000000000000
   1.6299999999999990    1.6299999999999990    1.6299999999999990
  -1.0000000000000000   -1.0000000000000000   -1.0000000000000000
   6.5199999999999900    6.5199999999999900    6.5199999999999900
    .9900000000000000     .9900000000000000     .9900000000000000
    .2700000000000000     .2700000000000000     .2700000000000000



Number of cases read:  6    Number of cases listed:  6

This is from the data window
 1.5500000000000000    1.5500000000000000    1.5500000000000000
 1.6299999999999990    1.6300000000000000    1.6300000000000000
-1.0000000000000000   -1.0000000000000000   -1.0000000000000000
 6.5199999999999910    6.5200000000000000    6.5200000000000000
  .9900000000000000     .9900000000000000     .9900000000000000
  .2700000000000000     .2700000000000000     .2700000000000000




On 7/29/2011 5:53 AM, Garry Gelade wrote:

Dear Simon

 

I am also using SPSS 18 under windows 7 64-bit. I attempted to reproduce your problem, and did so, but there’s something else. Here’s what happens to me.

 

DATA LIST list/x (F33.16) .

begin data.

1.5500000000000000

1.6299999999999990

-1.0000000000000000

6.5199999999999900

  .9900000000000000

  .2700000000000000

end data.

 

LIST.

 

1.5500000000000000

1.6299999999999990

-1.0000000000000000

6.5199999999999900

.9900000000000000

.2700000000000000

 

So far so good, but look at what is in the data editor.

 

1.5500000000000000

1.6299999999999990

-1.0000000000000000

6.5199999999999910

.9900000000000000

.2700000000000000

 

Can you see the difference? The fourth entry is different in the 15th place to what was specified in DATA LIST and reported by LIST.

 

Garry

 

 

From: SPSSX(r) Discussion [[hidden email]] On Behalf Of Simon Phillip Freidin
Sent: 29 July 2011 08:05
To: [hidden email]
Subject: Help with decimal places

 

Hi All

 

I have data which I thought was truncated to 2 decimal digit precision.

 

 However nothing I try stores it without imprecise repeating 9's (because it is stored as an exponential?; or is it a list and format problem?)

 

Test program below, I would have expected 1.6299999999999990 -> 1.6300000000000000

 

Can someone explain or give a workaround?

 

Does it have anything to do with system-wide fuzzbits?

 

thanks

Simon

 

data list list/x (f33.16).

begin data.

 1.5500000000000000

 1.6299999999999990

-1.0000000000000000

 6.5199999999999900

  .9900000000000000

  .2700000000000000

end data.

compute x=rnd(x*100)/100.

list/x.

compute x=trunc(x*100)/100.

list/x.

 

/* SPSS 18.0.2 & 19.0.0.1 on 64-bit Windows 7; i7 */

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Help with decimal places

David Marso
Administrator
Moral:  Some numbers do NOT have an precise 32 bit binary representation !
Notice what happens to ex 3 when formatted to 16 dec.  See also var FUBAR.
In a nutshell:  Don't worry go grab a homebrew or roll a blunt!!!

*with this modified syntax I get the output below.

data list list/x (f33.16).
begin data.
 1.5500000000000000
 1.6299999999999990
 1.6300000000000000
-1.0000000000000000
 6.5199999999999900
  .9900000000000000
  .2700000000000000
end data.
compute x100=x*100.
compute FUBAR=NUMBER(STRING(x,F4.2),F4.2).
compute x2=rnd(x100)/100.
compute x3=trunc(x100)/100.
formats x to x3 (f20.16).
list.

                   X                 X100                FUBAR                   X2                   X3

  1.5500000000000000 155.0000000000000000   1.5500000000000000   1.5500000000000000   1.5500000000000000
  1.6299999999999990 162.9999999999999000   1.6299999999999990   1.6299999999999990   1.6299999999999990
  1.6299999999999990 163.0000000000000000   1.6299999999999990   1.6299999999999990   1.6299999999999990
 -1.0000000000000000 -100.000000000000000  -1.0000000000000000  -1.0000000000000000  -1.0000000000000000
  6.5199999999999900 651.9999999999990000   6.5199999999999900   6.5199999999999900   6.5199999999999900
   .9900000000000000  99.0000000000000000    .9900000000000000    .9900000000000000    .9900000000000000
   .2700000000000000  27.0000000000000000    .2700000000000000    .2700000000000000    .2700000000000000


Number of cases read:  7    Number of cases listed:  7

formats x to x3 (f20.15).
list.



                   X                 X100                FUBAR                   X2                   X3

   1.550000000000000  155.000000000000000    1.550000000000000    1.550000000000000    1.550000000000000
   1.629999999999999  162.999999999999800    1.630000000000000    1.630000000000000    1.630000000000000
   1.630000000000000  163.000000000000000    1.630000000000000    1.630000000000000    1.630000000000000
  -1.000000000000000 -100.000000000000000   -1.000000000000000   -1.000000000000000   -1.000000000000000
   6.519999999999990  651.999999999999000    6.520000000000000    6.520000000000000    6.520000000000000
    .990000000000000   99.000000000000000     .990000000000000     .990000000000000     .990000000000000
    .270000000000000   27.000000000000000     .270000000000000     .270000000000000     .270000000000000


Number of cases read:  7    Number of cases listed:  7
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Help with decimal places

Richard Ristow
At 09:59 AM 7/29/2011, David Marso wrote:

>Some numbers do NOT have an precise 32 bit binary representation !

That is true enough, for any number of bits; but it's worth noting
that SPSS uses a number representation with 53, not 32, bits precision.

The moral is, don't rely on SPSS retaining the *exact* numerical
value for any non-integer quantity, or any integer with more than 16
digits (more precisely, any that exceeds 2**53=9,007,199,254,740,992).

At 03:04 AM 7/29/2011, Simon Phillip Freidin wrote:

>I have data which I thought was truncated to 2 decimal digit
>precision. However nothing I try stores it without imprecise
>repeating 9's (because it is stored as an exponential?; or is it a
>list and format problem?)

That's because SPSS's number format cannot represent the exact
two-decimal value, and has to instead store the nearest approximation to it.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Help with decimal places

Jon K Peck
It's also worth noting that SPSS, like most other software, relies on the IEEE floating point representation for numbers.  This really has nothing to do with SPSS software in particular but stems from standard floating point hardware.

Regards,

Jon Peck
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        Richard Ristow <[hidden email]>
To:        [hidden email]
Date:        07/29/2011 11:46 PM
Subject:        Re: [SPSSX-L] Help with decimal places
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




At 09:59 AM 7/29/2011, David Marso wrote:

>Some numbers do NOT have an precise 32 bit binary representation !

That is true enough, for any number of bits; but it's worth noting
that SPSS uses a number representation with 53, not 32, bits precision.

The moral is, don't rely on SPSS retaining the *exact* numerical
value for any non-integer quantity, or any integer with more than 16
digits (more precisely, any that exceeds 2**53=9,007,199,254,740,992).

At 03:04 AM 7/29/2011, Simon Phillip Freidin wrote:

>I have data which I thought was truncated to 2 decimal digit
>precision. However nothing I try stores it without imprecise
>repeating 9's (because it is stored as an exponential?; or is it a
>list and format problem?)

That's because SPSS's number format cannot represent the exact
two-decimal value, and has to instead store the nearest approximation to it.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD