Setting max value of 4294967295 for a Slider doesnt work


#1

The slider goes to 4294967295/2 then shows negative values. I think its because juce::Slider::Pimpl represents the values with double.

 

I need to represent -4294967295 to +4294967295.

 

Do I need to make a new slider type by copying out the juce::Slider class and changing the internal value representation to long double ?

I wonder if juce::Slider can be templated to accept the value type externally.

 

Why would I need such high values ? Well, because I need to represent the entire range of uint32_t so at least 0 to +4294967295 .

 


#2

A double is big enough to store that value with no problem. If it's going wrong, it must be because it's getting truncated to an integer somewhere. If you can point to somewhere in the code that needs changing, I'd be happy to take a look!


#3

Hi Jules,

 

You are right. The problem seems to be in the lable display. When trying to diplay the label, the value is converted into a String and it shows up as -1 in the UI.

 

Here is a simple project created from Introjucer that shows this.

http://www.filedropper.com/slidermaxmintest

 

A screenshot with the stack trace http://postimg.org/image/3uem07umn/

 

 


#4

I tracked down the place where the float gets truncated. It starts in Slider::getTextFromValue, where it calls

return String (roundToInt (v)) + getTextValueSuffix();

and this roundToInt function is implemented in juce_MathFunctions.h as follows (including only the relevant lines of code:

and this roundToInt function is implemented in juce_MathFunctions.h as follows (including only the relevant lines of code:

template <typename FloatType>
inline int roundToInt (const FloatType value) noexcept
{

    union { int asInt[2]; double asDouble; } n;
    n.asDouble = ((double) value) + 6755399441055744.0;

   #if JUCE_BIG_ENDIAN
    return n.asInt [1];
   #else
    return n.asInt [0];
   #endif
}

So you see it's truncated to an int right there.

What you could do to fix this from the app side is: derive from Slider, and reimplement getTextFromValue() for example like this:


String LongIntSlider::getTextFromValue (double v)
{
    return String ((int64) v) + getTextValueSuffix();
}

this will get rid of the problem.

The long-term solution is that we will likely fix it in the proper Slider class.


#5

Hi Timur,

 

Thanks so much for looking into this. Yes I overrode that function to get around the bug.