49 lines
2.2 KiB
Go
49 lines
2.2 KiB
Go
|
package number
|
|||
|
|
|||
|
import (
|
|||
|
"fmt"
|
|||
|
"regexp"
|
|||
|
)
|
|||
|
|
|||
|
var (
|
|||
|
FloatingPrecision uint64 = 10 // Nombre de chiffres après la virgule pour un nombre décimal ou un nombre scientifique
|
|||
|
FixedPrecision = false // Si vrai le nombre chiffre après la virgule est fixe.
|
|||
|
)
|
|||
|
|
|||
|
const (
|
|||
|
regSign = `\+|-`
|
|||
|
regBSign = `0|1`
|
|||
|
regBase = `\(\d+\)`
|
|||
|
regBase2 = `B|b`
|
|||
|
regBase8 = `O|o`
|
|||
|
regBase16 = `X|x`
|
|||
|
regNb = `[0-9a-zA-Z]`
|
|||
|
regNb2 = `0|1`
|
|||
|
regNb8 = `[0-7]`
|
|||
|
regNb10 = `\d`
|
|||
|
regNb16 = `[0-9a-fA-F]`
|
|||
|
regExp = `×\d+\^`
|
|||
|
regExp10 = `E|e`
|
|||
|
)
|
|||
|
|
|||
|
var (
|
|||
|
regInt = regexp.MustCompile(fmt.Sprintf(`%s(%s)?%s+`, regBase, regSign, regNb))
|
|||
|
regInt2 = regexp.MustCompile(fmt.Sprintf(`(%s)(%s)(%s)+`, regBSign, regBase2, regNb2))
|
|||
|
regInt8 = regexp.MustCompile(fmt.Sprintf(`(%s)(%s)(%s)+`, regBSign, regBase8, regNb8))
|
|||
|
regInt10 = regexp.MustCompile(fmt.Sprintf(`(%s)?%s+`, regSign, regNb10))
|
|||
|
regInt16 = regexp.MustCompile(fmt.Sprintf(`(%s)(%s)(%s)+`, regBSign, regBase16, regNb16))
|
|||
|
|
|||
|
regDec = regexp.MustCompile(fmt.Sprintf(`%s(%s)?(%s*\.%s+|%s+\.)`, regBase, regSign, regNb, regNb, regNb))
|
|||
|
regDec2 = regexp.MustCompile(fmt.Sprintf(`(%s)(%s)((%s)*\.(%s)+|(%s)+\.)`, regBSign, regBase2, regNb2, regNb2, regNb2))
|
|||
|
regDec8 = regexp.MustCompile(fmt.Sprintf(`(%s)(%s)((%s)*\.(%s)+|(%s)+\.)`, regBSign, regBase8, regNb8, regNb8, regNb8))
|
|||
|
regDec10 = regexp.MustCompile(fmt.Sprintf(`(%s)?(%s*\.%s+|%s+\.)`, regSign, regNb10, regNb10, regNb10))
|
|||
|
regDec16 = regexp.MustCompile(fmt.Sprintf(`(%s)(%s)((%s)*\.(%s)+|(%s)+\.)`, regBSign, regBase16, regNb16, regNb16, regNb16))
|
|||
|
|
|||
|
regFrac = regexp.MustCompile(fmt.Sprintf(`%s(%s)?%s+/(%s)?%s+`, regBase, regSign, regNb, regSign, regNb))
|
|||
|
regFrac10 = regexp.MustCompile(fmt.Sprintf(`(%s)?%s+/(%s)?%s+`, regSign, regNb10, regSign, regNb10))
|
|||
|
|
|||
|
regSci = regexp.MustCompile(fmt.Sprintf(`%s(%s)?(%s*\.%s+|%s+\.?)%s(%s)?(%s)+`, regBase, regSign, regNb, regNb, regNb, regExp, regSign, regNb10))
|
|||
|
regSci10Simple = regexp.MustCompile(fmt.Sprintf(`%s(%s)?(%s*\.%s+|%s+\.?)`, regSign, regNb10, regNb10, regNb10, regExp, regSign, regNb10))
|
|||
|
regSci10 = regexp.MustCompile(fmt.Sprintf(`%s(%s)?(%s*\.%s+|%s+\.?)`, regSign, regNb10, regNb10, regNb10, regExp10, regSign, regNb10))
|
|||
|
)
|