• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Scale Question for BigDecimal

 
Ranch Hand
Posts: 246
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been trying to do a few things with class BigDecimal, most recently by writing trigonometric functions for it. I have:

and

I've been getting pretty good results from this, but when I execute "java UseTrig 40 0" I get:

sin( 0) == 0.
cos( 0) == 1.0000000000000000000000000000000000000000.

Why do I get forty zeros after the decimal point for the cosine but no zeros at all after the decimal point for the sine? My guess is that this has something to do with the scale value, but I'm not sure what the scale value really does with BigDecimal, so I'd appreciate anybody trying to explain this for me.

Kevin S
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you set the scale to 40 so that's why you get 40 decimal places in the cosine.

But I'm guessing your question was really why you don't get 40 decimal places in the sine? That's because you initialize "sum" to zero without any scale (so, with scale zero) and then return it immediately, without doing any calculations, in this particular case.

(P.S. The name of the Greek letter ε is "epsilon", not "ebsilon". Sorry for being picky, I know it doesn't affect the results at all.)

 
Kevin Simonson
Ranch Hand
Posts: 246
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:But I'm guessing your question was really why you don't get 40 decimal places in the sine? That's because you initialize "sum" to zero without any scale (so, with scale zero) and then return it immediately, without doing any calculations, in this particular case.


Thanks for the response!

Paul Clapham wrote:(P.S. The name of the Greek letter ε is "epsilon", not "ebsilon". Sorry for being picky, I know it doesn't affect the results at all.)


Now that's just embarrassing. I've been using ebsilon all these years, not realizing it wasn't even a word!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic