Skip to content

Unhandled negative bps case #161

Description

@UltimateEvil

Don't ask me how to reproduce this consistently as I ahve no clue, but the error is annoying never the less

        miniYAxis.Labeler = (value) => value == 0 ? "0Bps" : FormatBytes(Math.Pow(10, value), "Bps");
        

calls
FormatBytes(Math.Pow(10, -10),"Bps")
Don't ask me how, did not go into debugging that much. This throws an index out of bounds.

Band-aid which should probably be kept in place in some way.

    private static string FormatBytes(double size, string? suffix = null)
    {
        bool neg = size < 0;
        string minus = "";
        if (neg)
        {
            minus = "-";
            size = -size;
        }
        var num = Math.Min(units.Length - 1, (int)Math.Log(size, 1000));
        size = (int)(size / Math.Pow(1000, num) * 100) / 100;
        return $"{minus}{size:#0.##}{units[num]}{suffix}";
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions