#problem here

21 messages · Page 1 of 1 (latest)

stray talon
#

this method aint working how its supposed to. It works for most cases, but not all for some reason. also not for -+ and -- max value what ever that shoudl mean. The following test cases are failing (also i cant use if statements, dont ask why :/):

Test Case · decryptFloat - RandomPositives failed
Some positive values seem to produce wrong number triplets

Test Case · decryptFloat - RandomNegatives failed
Some positive values seem to produce wrong number triplets

Test Case · decryptFloat - +MAX_VALUE failed
Did you consider all values?

Test Case · decryptFloat - -MAX_VALUE failed
Did you consider all values?

public String decryptFloat(float fx) {

    //float adjustedFx = (fx == Float.MAX_VALUE || fx == Float.MIN_VALUE) ? Float.NaN : fx;

    float value = (fx + mbox.getIntHint()) * mbox.getFloatHint();

    //float adjValue = (value == Float.MAX_VALUE || value == Float.MIN_VALUE) ? Float.NaN : value;

    double value1 = Math.abs(Math.cos(value));
    value1 = Math.max(-1.0, Math.min(1.0, value1));

    String value3 = String.format("%.3f", value1);
    String value4 = value3.replaceFirst("^0\\.0*", "");
    String value5 = value4.substring(value4.indexOf(".")+1);

    return value5;

}
crisp gardenBOT
#

This post has been reserved for your question.

Hey @stray talon! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

crisp gardenBOT
crisp gardenBOT
# stray talon this method aint working how its supposed to. It works for most cases, but not a...
this method aint working how its supposed to. It works for most cases, but not all for some reason. also not for -+ and -- max value what ever that shoudl mean. The following test cases are failing (also i cant use if statements, dont ask why :/):

Test Case · decryptFloat - RandomPositives failed
Some positive values seem to produce wrong number triplets

Test Case · decryptFloat - RandomNegatives failed
Some positive values seem to produce wrong number triplets

Test Case · decryptFloat - +MAX_VALUE failed
Did you consider all values?

Test Case · decryptFloat - -MAX_VALUE failed
Did you consider all values? 

public String decryptFloat(float fx) {

        //float adjustedFx = (fx == Float.MAX_VALUE || fx == Float.MIN_VALUE) ? Float.NaN : fx;

        float value = (fx + mbox.getIntHint()) * mbox.getFloatHint();

        //float adjValue = (value == Float.MAX_VALUE || value == Float.MIN_VALUE) ? Float.NaN : value;

        double value1 = Math.abs(Math.cos(value));
        value1 = Math.max(-1.0, Math.min(1.0, value1));

        String value3 = String.format("%.3f", value1);
        String value4 = value3.replaceFirst("^0\\.0*", "");
        String value5 = value4.substring(value4.indexOf(".")+1);

        return value5;

    }
hearty echo
#

What is the method supposed to do?

#

and what exactly doesn't work?

stray talon
hearty echo
#

not full test cases describing what the exact inputs and expected outputs are

stray talon
#

its supposed to get a float fx, add an int to it, then multiply by a float, then take cos of that value, then absolute value, then round to 3 decimal places and return those 3 decimal places.

stray talon
#

these "errors" are all i have

hearty echo
#

Why do you have the thing with Math.min and Math.max there?

#

We can't guess what you should do

stray talon
#

its supposed to make sure the value statys within those boundaries

#

in summary, there are certain floats that dont give me the right answer. chatgpt says causes could be how MINValue and MAXValue values are handled, rounding errors and that the number after the initial multiplication is too large

#

but i have no idea how to correct that without an if loop. thats what the min max methods are for

hearty echo
#

It isn't a comment

stray talon
#

shits impossible

stray talon
#

nvm got it