Calculate Num_Index_Pages for sizing design
Attempting to implement the same, I ended up using this to approximate at a decent level of accuracy:
WHILE (@NonLeafLevels &gt; 1)
BEGIN
    DECLARE @TempIndexPages FLOAT;

    -- TempIndexPages may be exceedingly small, so catch any arith overflows and call it 0
    BEGIN TRY
        SET @TempIndexPages = @NumLeafPages / POWER(@IndexRowsPerPage, @NonLeafLevels);
        SET @NumIndexPages = @NumIndexPages + @TempIndexPages;
        SET @NonLeafLevels = @NonLeafLevels - 1;
    END TRY
    BEGIN CATCH
        SET @NonLeafLevels = @NonLeafLevels - 1;
    END CATCH
END;