// Copyright 2017-2022 The MathJax Consortium
// SPDX-License-Identifier: Apache-2.0
// This file is a Go translation and modification of MathJax 3.2.2.

package mml

import (
	
	
	
	
	
)

// MactionSelectionNumber applies the numeric coercions used by the source
// maction selected getter to supported scalar attribute values.
func ( any,  bool) float64 {
	if ! {
		return math.NaN()
	}
	switch v := .(type) {
	case nil:
		return 0
	case bool:
		if  {
			return 1
		}
		return 0
	case int:
		return float64()
	case int64:
		return float64()
	case float64:
		return 
	case string:
		 := strings.TrimFunc(, mactionNumberSpace)
		if  == "" {
			return 0
		}
		if len() > 2 && [0] == '0' {
			 := 0
			switch [1] {
			case 'x', 'X':
				 = 16
			case 'b', 'B':
				 = 2
			case 'o', 'O':
				 = 8
			}
			if  != 0 {
				for ,  := range [2:] {
					 := int( - '0')
					if  >= 'a' &&  <= 'f' {
						 = int(-'a') + 10
					} else if  >= 'A' &&  <= 'F' {
						 = int(-'A') + 10
					}
					if  < 0 ||  >=  {
						return math.NaN()
					}
				}
				,  := new(big.Int).SetString([2:], )
				if ! {
					return math.NaN()
				}
				,  := .Float64()
				return 
			}
		}
		if mactionDecimalNumber.MatchString() {
			// A valid overflowing decimal converts to Infinity. ParseFloat's
			// range error must not turn it into NaN.
			,  := strconv.ParseFloat(, 64)
			return 
		}
	}
	return math.NaN()
}

// StringNumericLiteral accepts decimal/Infinity and unsigned radix literals;
// Go's parser additionally accepts Inf, hex floats and underscores, so validate
// the decimal grammar before conversion. Whitespace is the ECMAScript set,
// including BOM and excluding Unicode NEL (U+0085).
var mactionDecimalNumber = regexp.MustCompile(`^[+-]?(?:Infinity|(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?)$`)

func mactionNumberSpace( rune) bool {
	return  == '\t' ||  == '\n' ||  == '\v' ||  == '\f' ||  == '\r' ||  == ' ' ||
		 == '\u00a0' ||  == '\u1680' || ( >= '\u2000' &&  <= '\u200a') ||
		 == '\u2028' ||  == '\u2029' ||  == '\u202f' ||  == '\u205f' ||  == '\u3000' ||  == '\ufeff'
}