branch: externals/osc
commit 8d2b12496602c233f8796ece694044d71b5f4f16
Author: Mario Lang <[email protected]>
Commit: Mario Lang <[email protected]>
Improve single precision floating point serialisation
* packages/osc/osc.el: Update copyright years and author email.
* (osc-insert-float32): Use `copysign' and `isnan'.
---
osc.el | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/osc.el b/osc.el
index 9f92b17..316b532 100644
--- a/osc.el
+++ b/osc.el
@@ -1,8 +1,8 @@
;;; osc.el --- Open Sound Control protocol library
-;; Copyright (C) 2014 Free Software Foundation, Inc.
+;; Copyright (C) 2014-2019 Free Software Foundation, Inc.
-;; Author: Mario Lang <[email protected]>
+;; Author: Mario Lang <[email protected]>
;; Version: 0.1
;; Keywords: comm, processes, multimedia
@@ -57,15 +57,13 @@
(defun osc-insert-float32 (value)
(let (s (e 0) f)
(cond
- ((string= (format "%f" value) (format "%f" -0.0))
- (setq s 1 f 0))
- ((string= (format "%f" value) (format "%f" 0.0))
- (setq s 0 f 0))
+ ((= value 0.0)
+ (setq s (if (< (copysign 1.0 value) 0) 1 0) f 0))
((= value 1.0e+INF)
(setq s 0 e 255 f (1- (expt 2 23))))
((= value -1.0e+INF)
(setq s 1 e 255 f (1- (expt 2 23))))
- ((string= (format "%f" value) (format "%f" 0.0e+NaN))
+ ((isnan value)
(setq s 0 e 255 f 1))
(t
(setq s (if (>= value 0.0)