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
JavaBot
JavaBot3w ago
This post has been reserved for your question.
Hey @LordBeerus! 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.
JavaBot
JavaBot3w ago
Please format your code to make it more readable. For java, it should look like this:
​`​`​`​java
public void foo() {

}
​`​`​`​
​`​`​`​java
public void foo() {

}
​`​`​`​
JavaBot
JavaBot3w ago
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;

}
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;

}
dan1st
dan1st3w ago
What is the method supposed to do? and what exactly doesn't work?
LordBeerus
LordBeerusOP3w ago
the test cases that dont work are up there
dan1st
dan1st3w ago
these are just partial descriptions not full test cases describing what the exact inputs and expected outputs are
LordBeerus
LordBeerusOP3w ago
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
dan1st
dan1st3w ago
Why do you have the thing with Math.min and Math.max there? We can't guess what you should do
LordBeerus
LordBeerusOP3w ago
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
dan1st
dan1st3w ago
It isn't a comment
LordBeerus
LordBeerusOP2w ago
shits impossible nvm got it
JavaBot
JavaBot2w ago
💤 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.
Want results from more Discord servers?
Add your server