Function: hif-string-to-hexfloat
hif-string-to-hexfloat is a byte-compiled function defined in
hideif.el.gz.
Signature
(hif-string-to-hexfloat STRING &optional INT FRA EXP)
Documentation
Convert a C++17 hex float formatted string into float.
Assuming we've just regexp-matched with hif-hexfloat-regexp and it matched.
if REMATCH is t, do a rematch.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/hideif.el.gz
(defun hif-string-to-hexfloat (string &optional int fra exp)
"Convert a C++17 hex float formatted string into float.
Assuming we've just regexp-matched with `hif-hexfloat-regexp' and it matched.
if REMATCH is t, do a rematch."
;; This function relies on the regexp groups of `hif-hexfloat-regexp'
(let ((negate (if (eq ?- (aref string 0)) -1.0 1.0)))
(if (or int fra exp)
(setq int (hif-delete-char-in-string ?' int)
fra (hif-delete-char-in-string ?' fra)
exp (hif-delete-char-in-string ?' exp))
(setq string (hif-delete-char-in-string ?' string))
(hif-full-match hif-hexfloat-regexp string)
(setq int (or (match-string 1 string)
(match-string 3 string)
(match-string 5 string))
fra (or (match-string 2 string)
(match-string 4 string)
(match-string 6 string))
exp (match-string 7 string)))
(setq int (if (zerop (length int)) ;; nil or ""
0 (string-to-number int 16))
fra (if (zerop (length fra))
0 (/ (string-to-number fra 16)
(expt 16.0 (length fra))))
exp (if (zerop (length exp))
0 (string-to-number exp)))
(* negate (+ int fra) (expt 2.0 exp))))