format bugs, etc.

Started by kosh, December 12, 2009, 01:40:25 PM

Previous topic - Next topic

kosh

## 1. `format' function returns a value different from `printf()'


(format "%#05x" 10)
;-> ERR: problem in format string in function format : "%#05x"

(import "libc.so.6" "printf")
(printf "%#05x" 10)
;-> 0x00a
;=> 5

(format "%c" 0)
; => "" (empty string)

(printf "%c" 0)
;-> ^@ ("00")
;=> 1


## 2. `(rand 0)' returns not integer value.
(rand 0)
;=> true


---

kosh

cormullion

#1
(rand 0)'s different behaviour is  well-documented...



http://en.wikibooks.org/wiki/Introduction_to_newLISP/Working_with_numbers#Random_numbers">//http://en.wikibooks.org/wiki/Introduction_to_newLISP/Working_with_numbers#Random_numbers

http://www.newlisp.org/downloads/newlisp_manual.html#rand">//http://www.newlisp.org/downloads/newlisp_manual.html#rand



and  it's probably best that it doesn't return a number otherwise you might never notice that you asked for a random integer between 0 and -1... :)

kosh

#2
Quote(rand 0)'s different behaviour is well-documented...

mmm... I should check the documents.

sorry for misread the situation.

Lutz

#3
newLISP 'format' and C printf() are simply differemt things and on purpose. The C function returns the number of characters written, the 'format' function returns the the formatted string.



The format characters for 'format' are only a subset of what can be used in C and there are slight differences how integer precision is handled.



See the documentation for 'format' for details.