Character array is missing „e“ notation exponential mark

I observed that many people out there visiting my blog have great interest in a particular NumberFormatException. It goes by the message Character array is missing „e“ notation exponential mark and was mentioned in my post about fuzzing in Java.

Today we will take a more in depth look at it.

How does that NumberFormatException look like?

To visualize the error effectively, let’s look at the following extreme example drawn from my fuzzing post mentioned above.

Consider the following (sub-par implemented) function dollar2euro that takes any input (hopefully it’s a number though!) and tries to convert it from USD to EUR:

public String dollar2euro(Object input){
    BigDecimal inputParsed = new BigDecimal(input.toString());
    BigDecimal dollars = inputParsed.setScale(2, BigDecimal.ROUND_HALF_EVEN);

    BigDecimal multiply = dollars.multiply(BigDecimal.valueOf(0.92));
    BigDecimal euros = multiply.setScale(2, BigDecimal.ROUND_HALF_EVEN);
    return String.valueOf(euros);
}

Now what happens, if we play along the method signature and put in the following characters: „뤇皽“? If you know what they mean, feel free to drop me a comment down below. Please note that this is exactly what my fuzztest tried to do. And of course it drops a heavy NumberFormatException upon us:

Input: 뤇皽
java.lang.NumberFormatException: Character 뤇 is neither a decimal digit number, decimal point, nor "e" notation exponential mark.

And what does it mean?

The problem here is that „뤇皽“ is not a number. The first and second part Character 뤇 is neither a decimal digit number, decimal point are straight forward. But what does the third part nor „e“ notation exponential mark mean?

In maths, we have the option of expressing numbers in power form with base 10. This comes in handy when we want to express Googol (the number that inspired Google’s name) – a 1 with 100 zeroes. Accordingly we would write 10100 instead. In Java you can do something very similar, but there are better sources to check how to properly use the e-format. For our context let’s acknowledge that it is a different way of displaying numbers. Which likewise could not be found in our input.

But how do we fix that?

We have to make sure that we provide a String to the BigDecimal Constructor that looks like a valid number – if we want to provide a String at all. An actual number like a double or int would be even better. That would cost us no more than a change in the method’s signature and a small adaption to line 2. If we really want to provide a String, we still can do that, but then we have to make sure that it is properly formatted. A valid input example would be: „1337.012342„.

If you apply this simple rule, you should be spared from ‚Character array is missing „e“ notation exponential mark‘ errors in the future.

Conclusion

So long! I hope this little post gave you an idea about what the error message ‚Character array is missing „e“ notation exponential mark‘ means. Of course this case was kinda constructed and you probably have a less explicit case. If so, feel free to post it in the comments down below and we see what we can do. But for demonstration purposes it should have provided a clear image of what is going on in your program.

As my linked post about fuzzing in Java implies, I’m an avid test automation person. If you want more about automating tests with Java, check out my introduction tutorial about Selenium in Java. If you are more of the Python person, no problem. Here’s the same Selenium tutorial in Python. And if Python and Java are both too mainstream for you, I recommend my tutorial about Cucumber in Rust .

Happy test automating & have a nice day!

Home » Archives for Dezember 2023
Share it with:

Stable Diffusion: „LayerNormKernelImpl“ not implemented for ‚Half‘

Today I installed the Stable Diffusion Web UI by AUTOMATIC1111 on my ol‘ reliable Macbook Pro 2015 following this stable diffusion installation guide. And not only is it fun to do AI stuffs on an Intel Mac with no GPU whatsoever, of course I also had to run into a „first try error“ ™. This time it was that one:

RuntimeError: "LayerNormKernelImpl" not implemented for 'Half'

Okay, cool.

So how do we fix that?

Well it turns out that this „half“ thingy, that relates to floating point sizes, can be turned off. To do that, let’s revisit your stable-diffusion-webui installation directory and open the shell script webui-user.sh using your most beloved code editor. Here you will find the following 2 lines:

# Commandline arguments for webui.py, for example: export COMMANDLINE_ARGS="--medvram --opt-split-attention"
#export COMMANDLINE_ARGS=""

What we got to do now is: First we remove the leading ‚#‚ character of the second line to uncomment it. Next, we fill the variable with "--skip-torch-cuda-test --no-half" to make it look like this:

export COMMANDLINE_ARGS="--skip-torch-cuda-test --no-half"

Restart the stable diffusion web ui using your webui.sh and it should behave as expected. All of that has been tested with stable-diffusion-webui commit cf2772fab0af5573da775e7437e6acdca424f26e, which was the most recent stable version at the time of writing.

If you are on a Windows machine, the fix should be basically the same: Open the webui-user.bat and change COMMANDLINE_ARGS to match the following:

set COMMANDLINE_ARGS="--skip-torch-cuda-test --no-half"

Restart your server and everything should be alright. (Disclaimer: Untested due to the lack of Windows machines.)

Conclusion

So that’s all, hope this helps. If not, feel free to let me know in the comments below. If you find a better fix, or my post is outdated, or you found any other issues, please let me know as well. Let’s keep it as complete as possible for future users. And if you are still curious about working with Python apps or Python in general, here is another quick and handy post about handling environment variables. And here we talk about my second most favorite topic: Test Automation.

Best regards, and have a nice week!

Home » Archives for Dezember 2023

Share it with: