problem here
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;
}
12 Replies
⌛
This post has been reserved for your question.
Hey @LordBeerus! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose 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.
Please format your code to make it more readable. For java, it should look like this:
What is the method supposed to do?
and what exactly doesn't work?
the test cases that dont work are up there
these are just partial descriptions
not full test cases describing what the exact inputs and expected outputs are
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.
exactly, that my problem 😭
these "errors" are all i have
Why do you have the thing with Math.min and Math.max there?
We can't guess what you should do
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
It isn't a comment
shits impossible
nvm got it
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.