#Any potential issues with this method for getting rid of arbitrary floats

13 messages · Page 1 of 1 (latest)

lost matrix
#

Working on an interview task to identify improvements to an open source repository. There is a file that is full of manually typed out floating point approximations of rational numbers. Is this a reasonable suggestion to get rid of them?

template<int Numerator, int Denominator>
constexpr float RATIONAL()
{
    return static_cast<float>(Numerator) / static_cast<float>(Denominator);
}
low frigateBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

inland prawn
#

Uh, is there any reason why they can't just do constexpr float blah = 10.f / 13.f;?

#

You don't even need a function

lost matrix
#

(magic is the jargon for literals that arent defined anywhere right?)

#

lines like... making one up

#

x - 6.3436524234f > .4392372542f % 84.424253343f ? 73.27582357f

#

the template felt more readable to me for inline const expressions

#

what I tend to find readable is often different from what most people find readable which is my main reason for checking in

inland prawn
#

Having a function just to do division sounds like an overkill to me

#

But I'm not sure what their code looks like (your example wouldn't compile), and if you understood the question correctly

#

Maybe they wanted you to come up with x/y approximation for a decimal fraction?