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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:17:04+00:00 2026-06-11T14:17:04+00:00

I am trying to create a recursive method that uses Horner’s algorithm to convert

  • 0

I am trying to create a recursive method that uses Horner’s algorithm to convert a fractional number in base n to base 10. I’ve searched here and all over but couldn’t find anywhere that dealt with the fractional part in detail. As a heads up, I’m pretty weak in recursion as I have not formally learned it in my programming classes yet, but have been assigned it by another class.

I was able to make a method that handles the integer part of the number, just not the fractional part.

I feel like the method I’ve written is fairly close as it gets me to double the answer for my test figures (maybe because I’m testing base 2).

The first param passed is an int array filled with the coefficients. I’m not too concerned with the order of the coefficients as I’m making all the coefficients the same to test it out.

The second param is the base. The third param is initialized to the number of coefficients minus 1 which I also used for the integer part method. I tried using the number of coefficients, but that steps out of the array.

I tried dividing by the base one more time as that would give me the right answer, but it doesn’t work if I do so in the base case return statement or at the end of the final return statement.

So, when I try to convert 0.1111 base 2 to base 10, my method returns 1.875 (double the correct answer of 0.9375).

Any hints would be appreciated!

//TL;DR
coef[0] = 1; coef[1] = 1; coef[2] = 1; coef[3] = 1;
base = 2; it = 3;
//results in 1.875 instead of the correct 0.9375



public static double fracHorner(int[] coef, int base, int it) {
    if (it == 0) {
        return coef[it];
    }
    return ((float)1/base * fracHorner(coef, base, it-1)) + coef[it];
}
  • 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-11T14:17:05+00:00Added an answer on June 11, 2026 at 2:17 pm

    Observe that fracHorner always returns a value at least equal to coef[it] because it either returns coef[it] or something positive added to coef[it]. Since coef[it] >= 1 in your tests, it will always return a number greater than or equal to one.

    It’s relatively easy to fix: divide both coef[it] by base:

    public static double fracHorner(int[] coef, int base, int it) {
        if (it == 0) {
            return ((double)coef[it])/base;
        }
        return (fracHorner(coef, base, it-1) + coef[it])/base;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an image rotator class that cycles through an arbitrary number
I'm trying to create a bone and IK system. Below is the method that
The following code is how I'm trying to create a recursive binary method.. public
I'm trying to create a parser using Treetop that is somewhat recursive. An expression
I am trying create a delegate representation of constructor by emitting a Dynamic Method,
Ok so I am trying create a login script, here I am using PHP5
I'm trying to create a modulus function within haskell using primtive recursive functions. I
I am trying to create a text based menu in Python. Here is the
Following on from my question here , I'm trying to create a generic value
i use kohana framework and i am trying to code recursive function to create

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.