Does .NET have a built-in method to calculate the ULP of a given double or float?
If not, what is the most efficient way to do so?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
It seems the function is pretty trivial; this is based on the pseudocode in the accepted answer to the question linked by vulkanino:
For floats, you’d need to provide your own implementation of
SingleToInt32BitsandInt32BitsToSingle, since BitConverter doesn’t have those functions.This page shows the special cases in the java implementation of the function; handling those should be fairly trivial, too.