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

  • Home
  • SEARCH
  • 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 7435487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:04:58+00:00 2026-05-29T10:04:58+00:00

Possible Duplicate: Why do Python's math.ceil() and math.floor() operations return floats instead of integers?

  • 0

Possible Duplicate:
Why do Python's math.ceil() and math.floor() operations return floats instead of integers?

From the Python documentation of math.ceil…

math.ceil(x)
    Return the ceiling of x as a float, the smallest integer value greater than or equal to x.

Why did they consider float to be better? After all, the ceil of a number is by definition an integer and operations requiring real numbers can easily convert from int to float, but not necessarily the other way around, like in the case of [0] * ceil(x).

  • 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-29T10:04:59+00:00Added an answer on May 29, 2026 at 10:04 am

    There are floating point numbers that do not fit into an integer, so the function would fail if it returned an integer. Returning the same type as the parameter ensures the result will fit.

    Edit: Even though Python can represent very large integers, this wasn’t always the case. I don’t know when long integers were introduced, but until version 2.4 they didn’t intermix with regular integers very well. I assume that math.ceil was around before long integers were introduced, but I don’t have enough Python history to know for sure.

    The conversion from floating point to integer can also hold some surprises. By keeping the ceil function separate from the int conversion it’s easy to see which part is the source of the surprise.

    >>> math.ceil(1e23)
    1e+23
    >>> int(math.ceil(1e23))
    99999999999999991611392L
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Call Python From PHP And Get Return Code probably a very stupid
Possible Duplicate: Calling Python from Objective-C I'm a long-time Python programmer and short-time Cocoa
Possible Duplicate: How many Python classes should I put in one file? Coming from
Possible Duplicate: reverse a string in Python I tried searching the python documentation for
Possible Duplicate: How to get current python interpreter path from inside a Python script?
Possible Duplicate: python limiting floats to two decimal points i want to set 39.54484700000000
Possible Duplicate: Python is operator behaves unexpectedly with integers I stumbled upon the following
Possible Duplicate: Python: How to remove /n from a list element? I'm trying to
Possible Duplicate: Python try-else Comming from a Java background, I don't quite get what
Possible Duplicate: python limiting floats to two decimal points If I make this: 12.45-12

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.