Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Linux_x189

#1
Quote from: "cormullion"Don't forget to use + - * /  % rather than add sub mul div mod for integers...



If you find any errors or can add suggestions http://en.wikibooks.org/wiki/Introduction_to_newLISP/Working_with_numbers">//http://en.wikibooks.org/wiki/Introduction_to_newLISP/Working_with_numbers, please do! :)




Thx, I will check the website for some detiles.
#2
I think something may be wrong in newlisp.

I write my pow Integer-version of "pow" :

(define (** x y , (.pow 1)) (dotimes (i y) (set '.pow (* .pow x))))

and It just works fine with 9^17:

(** 9 17) returns:

16677181699666569



It's fine. So I continued:

(mod (** 9 17) 17) returns

8

It's wrong again!  



Now, I write my own mod funciton:

(define (mymod x y) (- x (* y (/ x y))))



(mymod (** 9 17) 17)



finally I get the right answer:

9



I think maybe some thing wrong with the "mod" function.

(** 9 17) is not a too big integer but "mod" failed to work
#3
Quote from: "cormullion"I don't think pow is big-integer friendly - has (pow 9 17) already exceeded 64-bit integer range and converted to float?



The addition of bigint into newLISP is very recent, and at the moment I don't think all arithmetic operations can handle them. newLISP isn't designed to be as maths-aware a language as some others, and you'll need to be careful how you switch between int, float, and bigint...


Newlisp does not have an Integer version of "pow" . (Theris is * for mul , / for div and so on...)

Ok, It looks like I should be careful of 'pow' when dealing with big numbers.

the length of (pow 9 17) is just 17 , not get out of the 64bit's limitation.
#4
Hi guys!

I am new to newlisp, and recently I encounting a really strange problem.



I type the following code in newlisp:

(mod (bigint (pow 9 17)) 17)



the answers  ( I typed it in windows xp(32bit) and Archlinux(64bit)) is:

10 (winxp)

8   (Archlinux)



but the answer should be 9.



And the 'pow' part is also quiet strange:

(bigint (pow 9 17))  returns 16677181699666570L

but the answer should be one less than that.



So, what is wrong I did. Or is it a bug?

Need some help ; )