float incr

mail@pastecode.io avatar
unknown
csharp
2 months ago
1.1 kB
2
Indexable
Never
public static long CountIncrementations(float delta)
{
    long incrementationsCount = 0;

    for (float value = 0; ; ++incrementationsCount)
    {
        float incrementedValue = value + delta;

        if (value == incrementedValue)
            break;

        value = incrementedValue;
    }

    for (float value = 0; ; ++incrementationsCount)
    {
        float incrementedValue = value - delta;

        if (value == incrementedValue)
            break;

        value = incrementedValue;
    }

    return incrementationsCount;
}

public static long CountIncrementations(double delta)
{
    long incrementationsCount = 0;

    for (double value = 0; ; ++incrementationsCount)
    {
        double incrementedValue = value + delta;

        if (value == incrementedValue)
            break;

        value = incrementedValue;
    }

    for (double value = 0; ; ++incrementationsCount)
    {
        double incrementedValue = value - delta;

        if (value == incrementedValue)
            break;

        value = incrementedValue;
    }

    return incrementationsCount;
}
Leave a Comment