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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:44:03+00:00 2026-06-14T17:44:03+00:00

I am trying to build an expression parser which evaluates the value of a

  • 0

I am trying to build an expression parser which evaluates the value of a mathematical expression. However the problem is for certain categories of expression which evaluates to an irrational number.

Lets take an example such as (√2)²
This should evaluate to 2 .However due to the logic the program is coded it returns a fractional point number.

First √2 is evaluated which equals 1.4142135 and then the result is squared giving 1.9999998

Presently, what all could do is to send the expression to Mathematica via JLink and then use the result. However this takes the help of a third party software.

I want to know if this whole thing can be implemented in java.

  • 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-14T17:44:05+00:00Added an answer on June 14, 2026 at 5:44 pm

    Yes, you can certainly implement an expression parser in Java. I think your fundamental error is not in Java programming but in program design.

    You should not be evaluating surds until as late as possible. Instead you should be evaluating expressions like (sqrt(n))^2 to sqrt(n)*sqrt(n) and sqrt(n)*sqrt(n) to n. Only then should you consider converting n into an equivalent floating-point number.

    What you have identified as an error in your approach is a feature of floating-point arithmetic which you will struggle to fight against. A better strategy is to work around it by implementing symbolic operations on symbolic expressions.

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

Sidebar

Related Questions

Hi all im trying to build a regular expression which will sustain the following
I'm trying to build a parser that can take a human language expression like
i am trying to build linq expression to solve my problem. I have list
I am trying to build a complex xpath expression which will answer the following
I'm trying to build an expression tree ( still ) but getting further! I
I'm trying to build s-expression objects using boost::proto with the following terminals: typedef proto::terminal<
I am trying to build a regular expression to extract the text inside the
I'm trying to build a switch and I get an expression must have integral
I'm trying build a method which returns the shortest path from one node to
I am trying to build an expression tree programmatically. I have in my input,

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.