Calculating a child object's Position, Rotation and Scale values?

I am making my own game editor, but have encountered the following problem:

I have two objects, A and B.

A's initial values:

Position: (3,3,3), Rotation: (45,10,0), Scale(1,2,2.5)

B's initial values:

Position: (1,1,1), Rotation: (10,34,18), Scale(1.5,2,1)

If I now make B a child of A, I need to re-calculate the B's Position, Rotation and Scale relative to A such that it maintains its current position, rotation and scale in world coordinates. So B's position would now be (-2, -2, -2) since now A is its center and (-2, -2, -2) will keep B in the same position.

I think I got the Position and scale figured out, but not rotation.

So I opened Unity and ran the same example and I noticed that when making a child object, the child object did not move at all. but had its Position, Rotation and Scale values changed relative to the parent.

For example:

Unity (Parent Object "A"):

Position: (0,0,0)
Rotation: (45,10,0)
Scale: (1,1,1)

Unity (Child Object "B"):

Position: (0,0,0)
Rotation: (0,0,0)
Scale: (1,1,1)

When B becomes a child of A, it's rotation values become:

X: -44.13605
Y: -14.00195
Z: 9.851074

If I plug the same rotation values into the B object in my editor, the object does not move at all.

How did Unity arrive at those rotation values for the child? What are the calculations?

If you can put all the equations for the Position, Rotation or Scale then I can double check I am doing it correctly but the Rotation is what I really need.