Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pattern matching on floating point values #8059

Closed
vicuna opened this issue Mar 13, 2003 · 2 comments
Closed

pattern matching on floating point values #8059

vicuna opened this issue Mar 13, 2003 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Mar 13, 2003

Original bug ID: 1590
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Brian Rogoff
Version: 3.06
OS: Solaris
Submission from: 192-149-105-50.artisan.com (192.149.105.50)

let fp_test x =
match x with
0. -> Printf.printf "MATCHED: x = 0\n"
| 90. -> Printf.printf "MATCHED: x = 90\n"
| 180. -> Printf.printf "MATCHED: x = 180\n"
| 270. -> Printf.printf "MATCHED: x = 270\n"
| _ -> Printf.printf "x = %g\n" x;;

Try this with values 0., 90., 180., 270. Results are:

fp_test 0.;;

MATCHED: x = 0

  • : unit = ()

fp_test 90.;;

x = 90

  • : unit = ()

fp_test 180.;;

MATCHED: x = 180

  • : unit = ()

fp_test 270.;;

MATCHED: x = 270

  • : unit = ()

When I run with -dlambda, I get this code for fp_test

(let
(fp_test/64
(function x/65
(catch
(if (<. x/65 270.)
(if (!=. x/65 0.)
(if (!=. x/65 180.) (exit 1)
(apply (field 1 (global Printf!)) "MATCHED: x = 180\n"))
(apply (field 1 (global Printf!)) "MATCHED: x = 0\n"))
(if (!=. x/65 270.)
(if (!=. x/65 90.) (exit 1)
(apply (field 1 (global Printf!)) "MATCHED: x = 90\n"))
(apply (field 1 (global Printf!)) "MATCHED: x = 270\n")))
with (1) (apply (field 1 (global Printf!)) "x = %g\n" x/65))))
(apply (field 1 (global Toploop!)) "fp_test" fp_test/64))

which will clearly (ahem! ;) never print "MATCHED: x = 90". So this code is
wrong
I think.

-- Brian

@vicuna
Copy link
Author

vicuna commented Mar 14, 2003

Comment author: administrator

Full_Name: Brian Rogoff
Version: 3.06

Snip << (Code uncovering a bug)

which will clearly (ahem! ;) never print "MATCHED: x = 90". So this code is
wrong
I think.

You are right to think so. This is a bug.
It is now corrected, thank you for having reported it.

-- Brian

--Luc

@vicuna
Copy link
Author

vicuna commented Mar 17, 2003

Comment author: administrator

Fixed on 03/04/2003 --Luc

@vicuna vicuna closed this as completed Mar 17, 2003
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant