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 6545917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:38:41+00:00 2026-05-25T11:38:41+00:00

When I call Math.ceil(5.2) the return is the double 6.0 . My natural inclination

  • 0

When I call Math.ceil(5.2) the return is the double 6.0. My natural inclination was to think that Math.ceil(double a) would return a long. From the documentation:

ceil(double a)

Returns the smallest (closest to negative infinity) double value
that is not less than the argument and is equal to a mathematical
integer.

But why return a double rather than a long when the result is an integer? I think understanding the reason behind it might help me understand Java a bit better. It also might help me figure out if I’ll get myself into trouble by casting to a long, e.g. is

long b = (long)Math.ceil(a);

always what I think it should be? I fear there could be some boundary cases that are problematic.

  • 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-25T11:38:42+00:00Added an answer on May 25, 2026 at 11:38 am

    The range of double is greater than that of long. For example:

    double x = Long.MAX_VALUE;
    x = x * 1000;
    x = Math.ceil(x);
    

    What would you expect the last line to do if Math.ceil returned long?

    Note that at very large values (positive or negative) the numbers end up being distributed very sparsely – so the next integer greater than integer x won’t be x + 1 if you see what I mean.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a simple call to the pow() function from math.h
I've noticed that when I call Math.Round and supply it with a decimal value
Having a bit of a drawing complication you would call it. My math is
I would like to create a function (call it fcreate) that when given a
i'm developing a math/statistical software. I would like that my customer can write something
Is there is a library for invoking math symbols/formula(not sure what to call), which
I call a javascript function from a textbox by using OnKeyPress=clickSearchButton() Here is my
I call addNotify() method in class that I posted here. The problem is, that
I call a certain div from another page with jquery to be loaded into
Someone has suggested to me that the built in C# Math.Sqrt function in .NET

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.