Convert GPS to coordinates on OpenStreetMap tiles image

Browsing maps in GPXsee will generate corresponding cache file, they are jpg images of the map tile matrix with a file name of zoomlevel-x-y with no suffix.
the path to these files is: %APPDATA%\GPXSee\
about zoom levels: https://wiki.openstreetmap.org/wiki/Zoom_levels

In reality we always get location in longitude and latitude while the map tiles are in coordinates, to load these tiles, we have to convert one to the other.
formuls are below:

longitude to x and latitude to y:

reverse:

constant z equals zoom level.

python code:

import math
lat = 20
long = 100
zoom = 10
x_b = 10000
y_b = 10000
pi = 3.141592653589793
x = (long + 180)/360 * pow(2,zoom)
y = (1-(math.log(math.tan(lat*pi/180)+1/math.cos(lat*pi/180))/pi))*pow(2, zoom-1)
print(x, y)

long_b = x/pow(2,zoom)*360 - 180
lat_b = math.atan(math.sinh(pi-y_b/pow(2,zoom)*2*pi))*180/pi
print(long_b, lat_b)

reference: 1, 2, 3