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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:19:16+00:00 2026-06-12T06:19:16+00:00

So in doing some of the Project Euler problems, I want to be able

  • 0

So in doing some of the Project Euler problems, I want to be able to take the square root of integer values (int, long, bigint, etc), but Sqrt is only defined for floating-point values. So I’ve been writing my own little Newton-Raphson algorithm, and it’s plenty accurate for what I need. However, I want to be able to call the built-in sqrt function on floating-point values. So I wrote something like this:

let inline dsqrt x =
    match box x with
    | :? float -> sqrt x
    | :? float32 -> sqrt x
    | _ -> p_dsqrt x

My function, obviously, is named “p_dsqrt”. However, this function requires that the input have a Sqrt method defined, which sort of defeats the whole purpose. Am I missing some type constraint, or what?

  • 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-12T06:19:17+00:00Added an answer on June 12, 2026 at 6:19 am

    I think you probably want this, instead:

    let dsqrt x =
        match box x with
        | :? float as f -> sqrt f |> box :?> 'a
        | :? float32 as f -> sqrt f |> box :?> 'a
        | _ -> p_dsqrt x
    

    The problem with your code is that you’re directly calling sqrt x, which constrains the possible types of x. In my modified code I bind a new identifier to the result of the successful coercion to float or float32, so this doesn’t put any constraint on the type of x.

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

Sidebar

Related Questions

I am doing some refactoring of my Delphi project. I want to be able
I am currently doing some Project Euler problems and the earlier ones often involve
so, i'm trying to learn ruby by doing some project euler questions, and i've
I'm doing a ASP.Net MVC2 project and i want to do some unit tests
I'm learning python, so I'm going through some Project Euler problems. I'm not sure
I've started some problems on Project Euler . One of the questions: The prime
I've been working on some problems/exercises on Project Euler hoping to practice/learn some optimal
I'm doing some Project Euler exercises and I've run into a scenario where I
I am trying to learn awk by doing some Project Euler questions. Here is
I'm writing some disposable Haskell scripts to solve some of the Project Euler problems.

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.