Ring of integers of a quadratic field (source code)

= Ring of integers of a quadratic field

For square-free $d\ne0,1$, an integral basis is $\{1,(1+\sqrt d)/2\}$ when $d\equiv1\pmod4$, and $\{1,\sqrt d\}$ otherwise. The discriminant is respectively $d$ and $4d$.