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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:26:51+00:00 2026-06-01T01:26:51+00:00

<math.h> provides a more accurate method for computing log(1+x) for double s. Is there

  • 0

<math.h> provides a more accurate method for computing log(1+x) for doubles.

Is there a similarly precise manner for computing log(1-x)?

The reason I ask is because I’m trying to do some work in log-space for greater precision (I’m mostly multiplying and summing numbers very close to zero). I found it easy to write a function that gives log( exp(log_of_a) + exp(log_of_b) ) = log( a + b ) by using log1p. I am trying to make a similar function for the difference:

log( exp(log_of_a) - exp(log_of_b) ) = log( a - b )
where a > b, of course.

Essentially, as long as neither log_a or log_b == -inf, the function should simply return:

return log( 1 - exp(log_b-log_a) ) + log_a;

In my log_add function, I end up with a log( 1 + ... ), and so I use log1p. But here I have log( 1 - ... ). Just in case, I even googled log1m, but no luck…

When the argument x is in the range [-inf, 1), then I could simply use log1p(-x) (given my assertion a > b).

Is that the best way to go about solving this? I feel I must be doing work that has been done before…

I’d really appreciate your help knowing how to get the most accurate results I can (or explaining why I can’t get results more accurate than this).

  • 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-06-01T01:26:53+00:00Added an answer on June 1, 2026 at 1:26 am

    @Raymond Chen is spot on: “Negation of floating point numbers is exact, so log1p(-x) is as accurate as log1p(x).” Just making it into a real answer.

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

Sidebar

Related Questions

The .net framework provides in the Math class a method for powering double. But
Math skills are becoming more and more essential, and I wonder where is a
math.h is not really a documentation. Is there something else that will describe these
There are some sites on the web that render LaTeX into some more readable
This question is about the threshold at which Math.Floor(double) and Math.Ceiling(double) decide to give
Should an API provide Rect::contains(Point) or Point::is_inside(Rect) or both? or Math::contains(Point, Rect) cause it's
Math escapes me today. How do I find the X speed and the Y
My math classes are far behind, and I'm currently struggling to find a decent
import math def p(n): return 393000*((288200/393000)^n * math.exp(-(288200/393000)))/math.factorial(n) print p(3) When I run it,
I suck at math. I need to figure out how to calculate a video

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.