Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 668717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:04:18+00:00 2026-05-14T00:04:18+00:00

Forgive me if this is a dumb beginners problem, but I really don’t get

  • 0

Forgive me if this is a dumb beginners problem, but I really don’t get it.

I have a member variable declared like so:

public Double Value;

When I assign 3.14159265 to Value and try to compute the sine of it, this happens:

system.out.println(Value.toString()); //outputs 3.14159265
Value = Math.sin(Value);
system.out.println(Value.toString()); //outputs NaN

In fact, this happens with every single value I tried – even with 0!
Math.sin() seems to always produce NaN as a result, regardless of the arguments value.

The docs say:

If the argument is NaN or an infinity, then the result is NaN.

But my argument is clearly not NaN or infinity!

What the heck is happening there?

UPDATE

Turns out I’m the dumbest programmer on earth. In my project the whole code is of course much more complex than the example above. It’s kind of an expression parser & evaluator and for the defined mathematical functions I use a switch-clause to decide which function to call – I forgot the break statement in the cases which caused the sqrt function to be executed with a negative parameter.

As I said – dumbest programmer on earth…

I accepted the topmost answer as it is the best imho. Sorry guys for wasting your time -.-

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:04:18+00:00Added an answer on May 14, 2026 at 12:04 am
    Double value = 3.14159265;
    System.out.println(value.toString()); //outputs 3.14159265
    value = Math.sin(value);
    System.out.println(value.toString()); //outputs NaN
    

    outputs (as expected):

    3.14159265
    3.5897930298416118E-9
    

    so problem should be somewhere else, which version of JDK are you using? is it 32 bit or 64 bit? is there other code in the middle that you didn’t paste?

    The only way to obtain a NaN from Math.sin is by using inf o NaN as the parameter. And without explicitly assign that value to a number you can obtain in just by doing wrong calculations, eg:

    Double d = 0.0/0.0;
    System.out.println(Math.sin(d));
    double d2 = Double.POSITIVE_INFINITY;
    System.out.println(Math.sin(d2));
    

    this will output: NaN twice.

    Two notes:

    • don’t use capitalized letters for variables (use value, not Value)
    • when you need stings as parameters (or composed to other strings) you don’t need to explicitly call toString(), you can do System.out.println(value)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Forgive me if this might be a dumb question but, I'm in an assembly
Forgive me if this is a simple problem but I can't seem to find
I'm new to flex , so forgive me if this is a dumb question.
I don't really get the concept of bytecode interpreter in the context of CPython.
Forgive me If this is a dumb question. Can one programmatically observe the contents
Forgive me if this is in the wrong place, but I figured a few
I never studied OSes, so forgive me if this sounds basic or silly, but
First of all please forgive me if its a really dumb question, I am
Forgive me if this is a simple question, but is a UISwitch a boolean
I'm new to jquery and asp.net so please forgive if this is an obvious

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.