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

Inconsistent --strict-math handling of certain properties (hardcoded font etc.) #1627

Closed
satya61229 opened this issue Oct 31, 2013 · 8 comments

Comments

@satya61229
Copy link

Some magic is happening in LESS. I used
ceil(@font-size-base * 1.25);
.. .
...
ceil(@font-size-base * 1.25);

First ceil was working but not the 2nd one. I was working with prepros downloaded recently. I checked in less2css.org there also same result. Now, it is working on less2css.

Another, issue was with this simple line of code:
@font-size-base * 1.25;

This was also used two times in my less. One for tablet and another for desktop with different number. First one was giving calculated number but another one was giving:
0.6em * 1.5; instead of calculated value.

I put the code here using which I was trying ceil and other:

http://stackoverflow.com/questions/19705791/why-this-less-css-is-failing

Also, "1em" with quote was coming whereas expected output was 1em.

@lukeapage
Copy link
Member

Sounds like strict maths is on? If it is you have to add parentheses around
every maths operation or it won't compute.

If its not that please give more repro steps and exactly what output or
error you get..
On 31 Oct 2013 13:44, "Satya Prakash" notifications@github.com wrote:

Some magic is happening in LESS. I used
ceil(@font-size-base * 1.25);

.. .
...
ceil(@font-size-base * 1.25);

First ceil was working but not the 2nd one. I was working with prepros
downloaded recently. I checked in less2css.org there also same result.
Now, it is working on less2css.

Another, issue was with this simple line of code:
@font-size-base * 1.25;

This was also used two times in my less. One for tablet and another for
desktop with different number. First one was giving calculated number but
another one was giving:
0.6em * 1.5; instead of calculated value.

I put the code here using which I was trying ceil and other:

http://stackoverflow.com/questions/19705791/why-this-less-css-is-failing

Also, "1em" with quote was coming whereas expected output was 1em.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1627
.

@satya61229
Copy link
Author

No, strict math was not on. The Code is still producing same result. The problem was with ceil as well but I have changed to make it work. Below code is not calculating. Here the code is not calculating:

// Mobile First Approach
@font-family-base:      "Helvetica Neue", Helvetica, Arial, sans-serif;
@font-color-base:       #4b4b4b;

@starting-font-size:        0.6em;

@font-size-base:            @starting-font-size;
@line-height-base:          1;
@letter-spacing-base:       -0.05em; 

@font-size-medium:          @font-size-base * 1.25;  //ceil(unit(@font-size-base) * 1.25)
@line-height-medium:        1.2;
@letter-spacing-medium:     0;

@font-size-large:           @font-size-base * 1.50; //ceil(unit(@font-size-base) * 1.50)
@line-height-large:         1.5;
@letter-spacing-large:      0.05em; 

@device-small : 24em;
@device-medium : 46.8em;
@device-large : 50em;


body{
font-family: @font-family-base;
font-size: @font-size-base;
line-height: @line-height-base;
color: @font-color-base;
word-wrap:break-word;

}

@media screen and (max-width:@device-medium) and (min-width: @device-small)
{
  /* Tablet */
  body {
    font-size:      @font-size-medium;
    line-height:    @line-height-medium;
    letter-spacing: @letter-spacing-medium;
  }
}
@media screen and (min-width: @device-large)
{
  /* Large screen */
  body {
    font:           @font-size-large;
    line-height:    @line-height-large;
    letter-spacing: @letter-spacing-large;
  }
}

Output in last media query:

@media screen and (min-width: 50em) {
  /* Large screen */
  body {
    font: 0.6em * 1.5;
    line-height: 1.5;
    letter-spacing: 0.05em;
  }
}

Just checked in less2css.org. Above output is coming there as well w/o strict math.

@seven-phases-max
Copy link
Member

@satya61229, see my answer here.
@lukeapage, it's in tree/rule.js:34.

@satya61229
Copy link
Author

Got it. It can be the case. Checked again in less2css.org and it work when changed to font-size from font. Accepted as right answer there. Thanks.

@scottgit
Copy link

scottgit commented Nov 5, 2013

@lukeapage I know satya61229 closed his own issue here, but I'm not sure that the "issue" is actually resolved. The fact that a function like ceil() would not do its math correctly because it was being called in a font: property when strict-math was off seems like a bug to me. I understand that the font property has the special case of needing to ignore the size/line-height syntax for math purposes, but that definitely should not affect maths inside functions, and is even questionable if it should affect any math outside a function except perhaps a division. To me, these should both resolve to 240px if strict-math is off:

 font: 12px * 20px;
 font-size: 12px * 20px;

I have not looked to see what other discussions you have had about font and the use of the size/line-height syntax, but I could even see spaces being important with strict-math off, so that:

 font: 12px/20px; // no math done in the font property
 font: 12px / 20px; // math done even in font property

However, that might be pushing it. Of course, all the above would require parenthesis if strict-math was on, no matter the operation or if it was in a function call like ceil().

@satya61229
Copy link
Author

For my purpose, working with LESS, it is resolved as I found a way to work. but from LESS own stability I agree with @scottgit . So, I am opening it. Hope you can close it later.

@satya61229 satya61229 reopened this Nov 5, 2013
@lukeapage
Copy link
Member

You are right, we switch on the option inside font declarationa but we should actually switch it off again for functions.

@seven-phases-max seven-phases-max changed the title There is some issue with ceil() and math calculation Inconsistent --strict-math handling of certain properties (hardcoded font etc.) Apr 17, 2016
@seven-phases-max
Copy link
Member

Merging to #1880 (since this one is impossible to "fix" w/o breaking a lot of things anyway).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants